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

@@ 415-437 (lines=23) @@
412
            }
413
        }
414
415
        if ($documentFound === false) {
416
417
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
418
            $xmlHackUsed = false;
419
            /** @noinspection StringFragmentMisplacedInspection */
420
            if (\stripos('<?xml', $html) !== 0) {
421
                $xmlHackUsed = true;
422
                $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
423
            }
424
425
            $this->document->loadHTML($html, $optionsXml);
426
427
            // remove the "xml-encoding" hack
428
            if ($xmlHackUsed) {
429
                foreach ($this->document->childNodes as $child) {
430
                    if ($child->nodeType === \XML_PI_NODE) {
431
                        /** @noinspection UnusedFunctionResultInspection */
432
                        $this->document->removeChild($child);
433
434
                        break;
435
                    }
436
                }
437
            }
438
        }
439
440
        // set encoding