private function extractHostname($url)
    {
        $url = trim(Str::lower($url));

        // Removes scheme and path i.e. "https://github.com/layershifter" to "github.com/layershifter".

        $url = preg_replace(static::SCHEMA_PATTERN, '', $url);

        // Removes path and query part of URL i.e. "github.com/layershifter" to "github.com".

        $url = $this->fixUriParts($url);
        $hostname = Arr::first(explode('/', $url, 2));

        // Removes username from URL i.e. user@github.com to github.com.

        $hostname = Arr::last(explode('@', $hostname));

        // Remove ports from hosts, also check for IPv6 literals like "[3ffe:2a00:100:7031::1]".
        //
        // @see http://www.ietf.org/rfc/rfc2732.txt

        $lastBracketPosition = Str::strrpos($hostname, ']');

        if ($lastBracketPosition !== false && Str::startsWith($hostname, '[')) {
            return Str::substr($hostname, 1, $lastBracketPosition - 1);
        }

        // This is either a normal hostname or an IPv4 address, just remove the port.

        $hostname = Arr::first(explode(':', $hostname));

        // If string is empty, null will be returned.

        return '' === $hostname ? null : $hostname;
    }