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;
    }