Code Duplication    Length = 23-29 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 2 locations

@@ 257-279 (lines=23) @@
254
        $this->node = $newNode;
255
256
        // Remove head element, preserving child nodes. (again)
257
        if (
258
            $this->node->parentNode instanceof \DOMElement
259
            &&
260
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
261
        ) {
262
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
263
264
            if ($this->node->parentNode->ownerDocument) {
265
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
266
                if ($html !== null) {
267
                    /** @var \DOMNode $html */
268
                    while ($html->childNodes->length > 0) {
269
                        $tmpNode = $html->childNodes->item(0);
270
                        if ($tmpNode !== null) {
271
                            /** @noinspection UnusedFunctionResultInspection */
272
                            $fragment->appendChild($tmpNode);
273
                        }
274
                    }
275
                    /** @noinspection UnusedFunctionResultInspection */
276
                    $html->parentNode->replaceChild($fragment, $html);
277
                }
278
            }
279
        }
280
281
        return $this;
282
    }
@@ 819-847 (lines=29) @@
816
        }
817
818
        // Remove head element, preserving child nodes.
819
        if (
820
            $removeExtraHeadTag
821
            &&
822
            $this->node->parentNode instanceof \DOMElement
823
            &&
824
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
825
        ) {
826
            $html = $this->node->parentNode->getElementsByTagName('head')[0] ?? null;
827
828
            if (
829
                $html !== null
830
                &&
831
                $this->node->parentNode->ownerDocument
832
            ) {
833
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
834
835
                /** @var \DOMNode $html */
836
                while ($html->childNodes->length > 0) {
837
                    $tmpNode = $html->childNodes->item(0);
838
                    if ($tmpNode !== null) {
839
                        /** @noinspection UnusedFunctionResultInspection */
840
                        $fragment->appendChild($tmpNode);
841
                    }
842
                }
843
844
                /** @noinspection UnusedFunctionResultInspection */
845
                $html->parentNode->replaceChild($fragment, $html);
846
            }
847
        }
848
849
        return $newDocument;
850
    }