protected static function buildAuthority(?string $userInfo, ?string $host, ?int $port): ?string
    {
        if ($host === null) {
            return null;
        }

        $authority = '';

        if ($userInfo !== null) {
            $authority .= sprintf('%s@', $userInfo);
        }
        $authority .= $host;
        if ($port !== null) {
            $authority .= sprintf(':%d', $port);
        }

        return $authority;
    }