Code Duplication    Length = 22-24 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 2 locations

@@ 511-532 (lines=22) @@
508
        $this->node = $newNode;
509
510
        // Remove head element, preserving child nodes. (again)
511
        if (
512
            $this->node->parentNode instanceof \DOMElement
513
            &&
514
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
515
        ) {
516
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
517
            if ($this->node->parentNode->ownerDocument !== null) {
518
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
519
                if ($html !== null) {
520
                    /** @var \DOMNode $html */
521
                    while ($html->childNodes->length > 0) {
522
                        $tmpNode = $html->childNodes->item(0);
523
                        if ($tmpNode !== null) {
524
                            /** @noinspection UnusedFunctionResultInspection */
525
                            $fragment->appendChild($tmpNode);
526
                        }
527
                    }
528
                    /** @noinspection UnusedFunctionResultInspection */
529
                    $html->parentNode->replaceChild($fragment, $html);
530
                }
531
            }
532
        }
533
534
        return $this;
535
    }
@@ 641-664 (lines=24) @@
638
        }
639
640
        // Remove head element, preserving child nodes.
641
        if (
642
            $removeExtraHeadTag
643
            &&
644
            $this->node->parentNode instanceof \DOMElement
645
            &&
646
            $newDocument->getIsDOMDocumentCreatedWithoutHeadWrapper()
647
        ) {
648
            $html = $this->node->parentNode->getElementsByTagName('head')[0];
649
            if ($this->node->parentNode->ownerDocument !== null) {
650
                $fragment = $this->node->parentNode->ownerDocument->createDocumentFragment();
651
                if ($html !== null) {
652
                    /** @var \DOMNode $html */
653
                    while ($html->childNodes->length > 0) {
654
                        $tmpNode = $html->childNodes->item(0);
655
                        if ($tmpNode !== null) {
656
                            /** @noinspection UnusedFunctionResultInspection */
657
                            $fragment->appendChild($tmpNode);
658
                        }
659
                    }
660
                    /** @noinspection UnusedFunctionResultInspection */
661
                    $html->parentNode->replaceChild($fragment, $html);
662
                }
663
            }
664
        }
665
666
        return $newDocument;
667
    }