public function withPort($port)
    {
        if ($port !== null) {
            $port = (int) $port;

            if (max(0, min(65535, $port)) !== $port) {
                throw new \InvalidArgumentException("Invalid port number '$port'");
            }
        }

        return $this->with('port', $port);
    }