Code Duplication    Length = 23-23 lines in 2 locations

src/voku/helper/XmlDomParser.php 1 location

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

src/voku/helper/HtmlDomParser.php 1 location

@@ 360-382 (lines=23) @@
357
            }
358
        }
359
360
        if ($documentFound === false) {
361
362
            // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
363
            $xmlHackUsed = false;
364
            /** @noinspection StringFragmentMisplacedInspection */
365
            if (\stripos('<?xml', $html) !== 0) {
366
                $xmlHackUsed = true;
367
                $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
368
            }
369
370
            $this->document->loadHTML($html, $optionsXml);
371
372
            // remove the "xml-encoding" hack
373
            if ($xmlHackUsed) {
374
                foreach ($this->document->childNodes as $child) {
375
                    if ($child->nodeType === \XML_PI_NODE) {
376
                        /** @noinspection UnusedFunctionResultInspection */
377
                        $this->document->removeChild($child);
378
379
                        break;
380
                    }
381
                }
382
            }
383
        }
384
385
        // set encoding