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

@@ 432-454 (lines=23) @@
429
            }
430
        }
431
432
        if ($documentFound === false) {
433
434
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
435
            $xmlHackUsed = false;
436
            /** @noinspection StringFragmentMisplacedInspection */
437
            if (\stripos('<?xml', $html) !== 0) {
438
                $xmlHackUsed = true;
439
                $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
440
            }
441
442
            $this->document->loadHTML($html, $optionsXml);
443
444
            // remove the "xml-encoding" hack
445
            if ($xmlHackUsed) {
446
                foreach ($this->document->childNodes as $child) {
447
                    if ($child->nodeType === \XML_PI_NODE) {
448
                        /** @noinspection UnusedFunctionResultInspection */
449
                        $this->document->removeChild($child);
450
451
                        break;
452
                    }
453
                }
454
            }
455
        }
456
457
        // set encoding