Validates and normalizes the port

@param int|null    $port The port
@param string|null $scheme The scheme

@return int|null
183714
protected static function normalizePort(?int $port, ?string $scheme): ?int
    {
        if ($port === null) {
            return null;
        }

        if ($scheme && isset(static::$defaultPorts[$scheme]) && ($port == static::$defaultPorts[$scheme])) {
            return null;
        }

        return $port;
    }
325425
public function getPort()
    {
        $port = $this->port;
        $default_ports = ['http' => 80,'https' => 443,'ftp' => 21];
        foreach ($default_ports as $scheme => $dp) {
            if ($this->scheme == $scheme && $port == $dp) {
                $port = null;
            }
        }
        return $port;
    }
134896
public function withPort($port): UriInterface
    {
        $port = $this->filterPort($port);

        $clone = clone $this;
        $clone->port = $port;

        return $clone;
    }
410557
public static int schemeToDefaultPort(final String scheme) {
		if(scheme.equals(HTTP_SCHEME)) {
			return 80;
		}
		if(scheme.equals(HTTPS_SCHEME)) {
			return 443;
		}
		if(scheme.equals(FTP_SCHEME)) {
			return 21;
		}
		if(scheme.equals(RTSP_SCHEME)) {
			return 554;
		}
		if(scheme.equals(MMS_SCHEME)) {
			return 1755;
		}
		return -1;
	}
620227
private function verify_port(int $port=null, string $proto) {
		if (!$port)
			return $port;
		if ($port < 0 || $port > pow(2, 16))
			return null;
		if ($port == 80 && $proto == 'http')
			return null;
		if ($port == 443 && $proto == 'https')
			return null;
		return $port;
	}
484516
public function port($port) {

		if(false === ('-' . intval($port) == '-' . $port)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($port)), E_USER_ERROR);
		}

		if($port < 1 || $port > 65535) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be between 1 and 65535, "%s" given', __METHOD__, $port), E_USER_ERROR);
		}

		$this -> options[CURLOPT_PORT] = intval($port);

		return $this;
	}
344973
public function port(int $defaultPort = null): int
    {

        if ($this->isHttp()) {
            return parent::port(Http::PORT);
        }

        return parent::port(Http::PORT_SSL);
    }
193765
public function setPort($port)
    {
        if (preg_match(self::PATTERN_MATCH_PORT, $port) !== 1) {
            throw new \InvalidArgumentException('"' . $port . '" is not valid port number as part of a URI.', 1184071241);
        }

        $this->port = (integer)$port;
    }
1363925
public function toHttp(int $port = null): self
    {
        if ($this->isHttp()) {
            if (null !== $port && !$this->parsedUri->portEquals($port)) {
                return new ConstructedHttpUri($this->parsedUri->transpose(['port' => $port]));
            }

            return $this;
        }

        $changes = ['scheme' => Http::SCHEME];
        if ($this->parsedUri->hasPort()) {
            $changes['port'] = $port;
        }

        return new ConstructedHttpUri($this->parsedUri->transpose($changes));
    }
290939
public function getPort()
    {
        if (null !== $this->port) {
            return $this->port;
        }

        $tmp = parse_url($this->getUrl());
        if (isset($tmp['port'])) {
            $this->setPort($tmp['port']);
        } elseif (isset($tmp['scheme'])) {
            $this->setPort(self::$defaultPorts[$tmp['scheme']]);
        }

        return $this->port;
    }
24977
public function port($port = null)
    {
        if (func_num_args() === 1) {
            $this->_port = $port;
            return $this;
        }
        if ($this->_port !== null) {
            return $this->_port;
        }
        $scheme = $this->_classes['scheme'];
        $name = $this->scheme();

        if ($scheme::registered($name)) {
            return $scheme::port($name);
        }
    }
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);
    }
1986
function getDefaultPortFromScheme( scheme ) {
  var port = null;
  if ( scheme === 'ftp') {
    port = 21;
  }
  else if ( scheme === 'gopher' ) {
    port = 70;
  }
  else if ( scheme === 'http' || scheme === 'ws' ) {
    port = 80;
  }
  else if ( scheme === 'https' || scheme === 'wss' ) {
    port = 443;
  }
  return port;
}
1200190
public function setScheme($scheme)
    {
        // Remove the default port if one is specified
        if ($this->port && isset(self::$defaultPorts[$this->scheme]) &&
            self::$defaultPorts[$this->scheme] == $this->port
        ) {
            $this->port = null;
        }

        $this->scheme = $scheme;

        return $this;
    }
739445
private function validate($port): ?int
    {
        $port = $this->filterComponent($port);
        if (null === $port) {
            return null;
        }

        $fport = filter_var($port, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]);
        if (false !== $fport) {
            return $fport;
        }

        throw new SyntaxError(sprintf('Expected port to be a positive integer or 0; received %s', $port));
    }
941419
protected function filterPort($port)
    {
        if ($port !== null) {
            $port = intval($port);

            if ($port < 1 || $port > 65535) {
                throw new InvalidArgumentException(sprintf('Invalid port "%s".', $port));
            }
        } else {
            $port = null;
        }

        return $port;
    }
1118906
public function setPort($port)
    {
        if (!empty($port)) {
            $this->port = intval($port);
        }
        else {
            $this->port = null;
        }

        return $this;
    }