Code Duplication    Length = 22-24 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 2 locations

@@ 243-264 (lines=22) @@
240
        $this->node = $newNode;
241
242
        // Remove head element, preserving child nodes. (again)
243
        if (
244
            $this->node->parentNode instanceof \DOMElement
245
            &&
246
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
247
        ) {
248
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
249
            if ($this->node->parentNode->ownerDocument !== null) {
250
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
251
                if ($html !== null) {
252
                    /** @var \DOMNode $html */
253
                    while ($html->childNodes->length > 0) {
254
                        $tmpNode = $html->childNodes->item(0);
255
                        if ($tmpNode !== null) {
256
                            /** @noinspection UnusedFunctionResultInspection */
257
                            $fragment->appendChild($tmpNode);
258
                        }
259
                    }
260
                    /** @noinspection UnusedFunctionResultInspection */
261
                    $html->parentNode->replaceChild($fragment, $html);
262
                }
263
            }
264
        }
265
266
        return $this;
267
    }
@@ 791-814 (lines=24) @@
788
        }
789
790
        // Remove head element, preserving child nodes.
791
        if (
792
            $removeExtraHeadTag
793
            &&
794
            $this->node->parentNode instanceof \DOMElement
795
            &&
796
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
797
        ) {
798
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
799
            if ($this->node->parentNode->ownerDocument !== null) {
800
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
801
                if ($html !== null) {
802
                    /** @var \DOMNode $html */
803
                    while ($html->childNodes->length > 0) {
804
                        $tmpNode = $html->childNodes->item(0);
805
                        if ($tmpNode !== null) {
806
                            /** @noinspection UnusedFunctionResultInspection */
807
                            $fragment->appendChild($tmpNode);
808
                        }
809
                    }
810
                    /** @noinspection UnusedFunctionResultInspection */
811
                    $html->parentNode->replaceChild($fragment, $html);
812
                }
813
            }
814
        }
815
816
        return $newDocument;
817
    }