Code Duplication    Length = 23-23 lines in 2 locations

src/voku/helper/HtmlDomParser.php 1 location

@@ 372-394 (lines=23) @@
369
            }
370
        }
371
372
        if ($documentFound === false) {
373
374
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
375
            $xmlHackUsed = false;
376
            /** @noinspection StringFragmentMisplacedInspection */
377
            if (\stripos('<?xml', $html) !== 0) {
378
                $xmlHackUsed = true;
379
                $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
380
            }
381
382
            $this->document->loadHTML($html, $optionsXml);
383
384
            // remove the "xml-encoding" hack
385
            if ($xmlHackUsed) {
386
                foreach ($this->document->childNodes as $child) {
387
                    if ($child->nodeType === \XML_PI_NODE) {
388
                        /** @noinspection UnusedFunctionResultInspection */
389
                        $this->document->removeChild($child);
390
391
                        break;
392
                    }
393
                }
394
            }
395
        }
396
397
        // set encoding

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