private static function myParseHostname(string $hostname, ?HostInterface &$host = null, ?string &$error = null): bool
    {
        if (strlen($hostname) > 2 && substr($hostname, 0, 1) === '[' && substr($hostname, -1) === ']') {
            // Hostname is actually an IP address.
            $ipAddress = substr($hostname, 1, -1);

            try {
                $host = Host::fromIPAddress(IPAddress::parse($ipAddress));
            } catch (IPAddressInvalidArgumentException $exception) {
                $error = $exception->getMessage();

                return false;
            }

            return true;
        }

        try {
            $host = Host::fromHostname(Hostname::parse($hostname));
        } catch (HostnameInvalidArgumentException $exception) {
            $error = $exception->getMessage();

            return false;
        }

        return true;
    }