Code Duplication    Length = 22-24 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 2 locations

@@ 232-253 (lines=22) @@
229
        $this->node = $newNode;
230
231
        // Remove head element, preserving child nodes. (again)
232
        if (
233
            $this->node->parentNode instanceof \DOMElement
234
            &&
235
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
236
        ) {
237
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
238
            if ($this->node->parentNode->ownerDocument !== null) {
239
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
240
                if ($html !== null) {
241
                    /** @var \DOMNode $html */
242
                    while ($html->childNodes->length > 0) {
243
                        $tmpNode = $html->childNodes->item(0);
244
                        if ($tmpNode !== null) {
245
                            /** @noinspection UnusedFunctionResultInspection */
246
                            $fragment->appendChild($tmpNode);
247
                        }
248
                    }
249
                    /** @noinspection UnusedFunctionResultInspection */
250
                    $html->parentNode->replaceChild($fragment, $html);
251
                }
252
            }
253
        }
254
255
        return $this;
256
    }
@@ 753-776 (lines=24) @@
750
        }
751
752
        // Remove head element, preserving child nodes.
753
        if (
754
            $removeExtraHeadTag
755
            &&
756
            $this->node->parentNode instanceof \DOMElement
757
            &&
758
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
759
        ) {
760
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
761
            if ($this->node->parentNode->ownerDocument !== null) {
762
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
763
                if ($html !== null) {
764
                    /** @var \DOMNode $html */
765
                    while ($html->childNodes->length > 0) {
766
                        $tmpNode = $html->childNodes->item(0);
767
                        if ($tmpNode !== null) {
768
                            /** @noinspection UnusedFunctionResultInspection */
769
                            $fragment->appendChild($tmpNode);
770
                        }
771
                    }
772
                    /** @noinspection UnusedFunctionResultInspection */
773
                    $html->parentNode->replaceChild($fragment, $html);
774
                }
775
            }
776
        }
777
778
        return $newDocument;
779
    }