Code Duplication    Length = 23-25 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 2 locations

@@ 253-275 (lines=23) @@
250
        $this->node = $newNode;
251
252
        // Remove head element, preserving child nodes. (again)
253
        if (
254
            $this->node->parentNode instanceof \DOMElement
255
            &&
256
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
257
        ) {
258
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
259
260
            if ($this->node->parentNode->ownerDocument !== null) {
261
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
262
                if ($html !== null) {
263
                    /** @var \DOMNode $html */
264
                    while ($html->childNodes->length > 0) {
265
                        $tmpNode = $html->childNodes->item(0);
266
                        if ($tmpNode !== null) {
267
                            /** @noinspection UnusedFunctionResultInspection */
268
                            $fragment->appendChild($tmpNode);
269
                        }
270
                    }
271
                    /** @noinspection UnusedFunctionResultInspection */
272
                    $html->parentNode->replaceChild($fragment, $html);
273
                }
274
            }
275
        }
276
277
        return $this;
278
    }
@@ 810-834 (lines=25) @@
807
        }
808
809
        // Remove head element, preserving child nodes.
810
        if (
811
            $removeExtraHeadTag
812
            &&
813
            $this->node->parentNode instanceof \DOMElement
814
            &&
815
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
816
        ) {
817
            $html = $this->node->parentNode->getElementsByTagName('head')[0] ?? null;
818
819
            if ($html !== null && $this->node->parentNode->ownerDocument !== null) {
820
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
821
822
                /** @var \DOMNode $html */
823
                while ($html->childNodes->length > 0) {
824
                    $tmpNode = $html->childNodes->item(0);
825
                    if ($tmpNode !== null) {
826
                        /** @noinspection UnusedFunctionResultInspection */
827
                        $fragment->appendChild($tmpNode);
828
                    }
829
                }
830
831
                /** @noinspection UnusedFunctionResultInspection */
832
                $html->parentNode->replaceChild($fragment, $html);
833
            }
834
        }
835
836
        return $newDocument;
837
    }