Sets the port number

@param int|null $port
@return $this
422079
public function setPort($port)
    {
        if ( ! is_null($port)) $port = (int) $port;

        $this->setAttribute('port', $port);

        return $this;
    }
1227016
public function setPort($port = null)
    {
        if (is_null($port) || is_int($port)) {
            $this->port = $port;
        }
        else if (is_string($port) && preg_match('/^[0-9]+$/', $port) !== 0) {
            $this->port = (int) $port;
        }
        else {
            throw new \InvalidArgumentException(
                "invalid value provided for 'port'; ".
                "expecting an integer, string of integers, or null"
            );
        }
        return $this;
    }
362998
protected function marshalPort($port): ? int
    {
        if ( null === $port ) {
            return null;
        }

        $port = (int) $port;

        if ( 0 > $port || 65535 < $port ) {
            throw new UriException(
                sprintf('Invalid port: %s, value must be between 0 and 65535', $port)
            );
        }

        return $port;
    }
852876
public function setPort($port)
    {
        $this->port = StdObjectWrapper::toString($port);
        $this->rebuildUrl();

        return $this;
    }
616690
public function setTargetPort($targetPort)
    {
        if (
               $this->getAddressType() != AF_UNIX
            && !is_integer($targetPort)
        ) {
            throw new \InvalidArgumentException('Target port parameter must be an integer');
        }
        $this->targetPort = $targetPort;

        return $this;
    }
1293734
private function filterPort($port)
    {
        if ($port === null) {
            return $port;
        }

        if (!preg_match('#^[0-9]+$#', (string) $port)) {
            throw new \InvalidArgumentException(sprintf('Invalid port "%s".', $port));
        }

        return (int) $port;
    }
685875
public function setPort(int $port): void
    {
        if ($port < 0 || $port > static::HIGHEST_PORT) {
            throw new \InvalidArgumentException('Port must be an unsigned integer on the range [0-65535]');
        }

        $this->port = $port;
    }
302692
public function setPort( $port ) : PgSQL
   {

      if ( null === $port )
      {
         $this->_attributes[ 'port' ] = $port;
         return $this;
      }

      $port = false;
      if ( \is_string( $port ) )
      {
         $port = (int) $port;
      }
      else if ( TypeTool::IsInteger( $port ) )
      {
         $port = (int) $port;
      }
      else if ( TypeTool::IsStringConvertible( $port, $portStr ) )
      {
         $port = (int) $portStr;
      }

      if ( ! \is_int( $port ) || ! $this->_supportedAttributes->get( 'port' )->validateValue( $port ) )
      {
         throw new ArgumentException( 'port', $port, 'Invalid port!' );
      }

      $this->_attributes[ 'port' ] = $port;

      return $this;

   }
842116
@Nonnull
  public final JettyStarter setPort (@Nonnegative final int nPort)
  {
    ValueEnforcer.isGT0 (nPort, "Port");
    m_nPort = nPort;
    return this;
  }
686711
public function withPort(int $port): UrlInterface
    {
        if (!self::myValidatePort($port, $error)) {
            throw new UrlInvalidArgumentException($error);
        }

        return new self($this->myScheme, $this->myHost, $port, $this->myPath, $this->myQueryString, $this->myFragment);
    }
743787
protected function filterPort($port)
    {
        if (empty($port)) {
            return null;
        }

        if (!self::validePort($port)) {
            throw new \InvalidArgumentException('The port is not in the TCP/UDP port.');
        }

        return $this->scheme !== '' && !$this->validPortStandard($port)
            ? (int) $port
            : null;
    }
189689
public function setDefaultHost($host, $port = null) {
		$this->defaultHost = (string) $host;
		
		if ($port !== null) {
			$this->setDefaultPort($port);
		}
		
		return $this;
	}
508365
public function getPort($port_num)
    {
        $ports = $this->server->ports;
        foreach ($ports as $port) {
            if ($port->port == $port_num) {
                return $port;
            }
        }

        return null;
    }
787274
function setPort($port)
    {
        if ($port !== null) {
            if (empty($port) && $port !== 0)
                $port = null;
            elseif ($port < 1 || $port > 65535)
                throw new \InvalidArgumentException(sprintf(
                    'Invalid port "%d" specified; must be a valid TCP/UDP port',
                    $port
                ));
        }

        $this->port = $port;
        return $this;
    }
85308
public function assertPortIsNot($port)
    {
        $actual = parse_url($this->driver->getCurrentURL(), PHP_URL_PORT) ?? '';

        PHPUnit::assertNotEquals(
            $port, $actual,
            "Port [{$port}] should not equal the actual value."
        );

        return $this;
    }
176688
private function formatPort($port = null): ?int
    {
        if (null === $port || '' === $port) {
            return null;
        }

        if (!is_int($port) && !(is_string($port) && 1 === preg_match('/^\d*$/', $port))) {
            throw new SyntaxError(sprintf('The port `%s` is invalid', $port));
        }

        $port = (int) $port;
        if (0 > $port) {
            throw new SyntaxError(sprintf('The port `%s` is invalid', $port));
        }

        $defaultPort = self::SCHEME_DEFAULT_PORT[$this->scheme] ?? null;
        if ($defaultPort === $port) {
            return null;
        }

        return $port;
    }
446331
public function connect($host = null, $port = null)
    {
        return $this->driver->connect(
            $host ? $host : $this->host,
            $port ? $port : $this->port
        );
    }