Code Duplication    Length = 24-26 lines in 2 locations

src/voku/helper/HtmlDomParser.php 1 location

@@ 452-477 (lines=26) @@
449
            }
450
        }
451
452
        if ($documentFound === false) {
453
454
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
455
            $xmlHackUsed = false;
456
            /** @noinspection StringFragmentMisplacedInspection */
457
            if (\stripos('<?xml', $html) !== 0) {
458
                $xmlHackUsed = true;
459
                $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
460
            }
461
462
            if ($html !== '') {
463
                $this->document->loadHTML($html, $optionsXml);
464
            }
465
466
            // remove the "xml-encoding" hack
467
            if ($xmlHackUsed) {
468
                foreach ($this->document->childNodes as $child) {
469
                    if ($child->nodeType === \XML_PI_NODE) {
470
                        /** @noinspection UnusedFunctionResultInspection */
471
                        $this->document->removeChild($child);
472
473
                        break;
474
                    }
475
                }
476
            }
477
        }
478
479
        // set encoding
480
        $this->document->encoding = $this->getEncoding();

src/voku/helper/XmlDomParser.php 1 location

@@ 185-208 (lines=24) @@
182
            }
183
        }
184
185
        if ($documentFound === false) {
186
187
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
188
            $xmlHackUsed = false;
189
            /** @noinspection StringFragmentMisplacedInspection */
190
            if (\stripos('<?xml', $xml) !== 0) {
191
                $xmlHackUsed = true;
192
                $xml = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $xml;
193
            }
194
195
            $documentFound = $this->document->loadXML($xml, $optionsXml);
196
197
            // remove the "xml-encoding" hack
198
            if ($xmlHackUsed) {
199
                foreach ($this->document->childNodes as $child) {
200
                    if ($child->nodeType === \XML_PI_NODE) {
201
                        /** @noinspection UnusedFunctionResultInspection */
202
                        $this->document->removeChild($child);
203
204
                        break;
205
                    }
206
                }
207
            }
208
        }
209
210
        if (
211
            $documentFound === false