Code Duplication    Length = 23-23 lines in 2 locations

src/voku/helper/XmlDomParser.php 1 location

@@ 150-172 (lines=23) @@
147
            }
148
        }
149
150
        if ($documentFound === false) {
151
152
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
153
            $xmlHackUsed = false;
154
            /** @noinspection StringFragmentMisplacedInspection */
155
            if (\stripos('<?xml', $xml) !== 0) {
156
                $xmlHackUsed = true;
157
                $xml = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $xml;
158
            }
159
160
            $this->document->loadXML($xml, $optionsXml);
161
162
            // remove the "xml-encoding" hack
163
            if ($xmlHackUsed) {
164
                foreach ($this->document->childNodes as $child) {
165
                    if ($child->nodeType === \XML_PI_NODE) {
166
                        /** @noinspection UnusedFunctionResultInspection */
167
                        $this->document->removeChild($child);
168
169
                        break;
170
                    }
171
                }
172
            }
173
        }
174
175
        // set encoding

src/voku/helper/HtmlDomParser.php 1 location

@@ 383-405 (lines=23) @@
380
            }
381
        }
382
383
        if ($documentFound === false) {
384
385
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
386
            $xmlHackUsed = false;
387
            /** @noinspection StringFragmentMisplacedInspection */
388
            if (\stripos('<?xml', $html) !== 0) {
389
                $xmlHackUsed = true;
390
                $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
391
            }
392
393
            $this->document->loadHTML($html, $optionsXml);
394
395
            // remove the "xml-encoding" hack
396
            if ($xmlHackUsed) {
397
                foreach ($this->document->childNodes as $child) {
398
                    if ($child->nodeType === \XML_PI_NODE) {
399
                        /** @noinspection UnusedFunctionResultInspection */
400
                        $this->document->removeChild($child);
401
402
                        break;
403
                    }
404
                }
405
            }
406
        }
407
408
        // set encoding