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;
    }
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;
    }
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 ; }
Format the Port component.

@param null|mixed $port
Format the Port component .