Code Duplication    Length = 23-23 lines in 2 locations

src/voku/helper/HtmlDomParser.php 1 location

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

src/voku/helper/XmlDomParser.php 1 location

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