Code Duplication    Length = 25-29 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 2 locations

@@ 259-283 (lines=25) @@
256
        $this->node = $newNode;
257
258
        // Remove head element, preserving child nodes. (again)
259
        if (
260
            $this->node->parentNode instanceof \DOMElement
261
            &&
262
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
263
        ) {
264
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
265
266
            if (
267
                $html !== null
268
                &&
269
                $this->node->parentNode->ownerDocument
270
            ) {
271
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
272
                /** @var \DOMNode $html */
273
                while ($html->childNodes->length > 0) {
274
                    $tmpNode = $html->childNodes->item(0);
275
                    if ($tmpNode !== null) {
276
                        /** @noinspection UnusedFunctionResultInspection */
277
                        $fragment->appendChild($tmpNode);
278
                    }
279
                }
280
                $html->parentNode->replaceChild($fragment, $html);
281
            }
282
        }
283
284
        return $this;
285
    }
286
@@ 865-893 (lines=29) @@
862
        }
863
864
        // Remove head element, preserving child nodes.
865
        if (
866
            $removeExtraHeadTag
867
            &&
868
            $this->node->parentNode instanceof \DOMElement
869
            &&
870
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
871
        ) {
872
            $html = $this->node->parentNode->getElementsByTagName('head')[0] ?? null;
873
874
            if (
875
                $html !== null
876
                &&
877
                $this->node->parentNode->ownerDocument
878
            ) {
879
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
880
881
                /** @var \DOMNode $html */
882
                while ($html->childNodes->length > 0) {
883
                    $tmpNode = $html->childNodes->item(0);
884
                    if ($tmpNode !== null) {
885
                        /** @noinspection UnusedFunctionResultInspection */
886
                        $fragment->appendChild($tmpNode);
887
                    }
888
                }
889
890
                $html->parentNode->replaceChild($fragment, $html);
891
            }
892
        }
893
894
        return $newDocument;
895
    }
896