private function filterPort($scheme, $host, $port)
    {
        if (null !== $port) {
            $port = (int) $port;
            if (1 > $port || 65535 < $port) {
                throw new \InvalidArgumentException(sprintf('Invalid port: %d. Must be between 1 and 65535', $port));
            }
        }

        return self::isStandardPort($port, (string) $scheme, (string) $host) ? null : $port;
    }