private function getDomDocumentType(string $data): string
    {
        $startPos = $endPos = \stripos($data, '<!doctype');
        $braces = 0;
        do {
            $char = $data[$endPos++];
            if ('<' === $char) {
                ++$braces;
            }
            if ('>' === $char) {
                --$braces;
            }
        } while ($braces > 0);

        $internalSubset = \substr($data, $startPos, $endPos - $startPos);
        $internalSubset = \str_replace(["\n", "\r"], '', $internalSubset);
        $internalSubset = \preg_replace('/\s{2,}/', ' ', $internalSubset);
        $internalSubset = \str_replace(['[ <!', '> ]>'], ['[<!', '>]>'], $internalSubset);

        return $internalSubset;
    }