Code Duplication    Length = 36-39 lines in 2 locations

src/Tokens/Elements/Head.php 1 location

@@ 34-72 (lines=39) @@
31
        $this->prependChild($title);
32
    }
33
34
    protected function removeInvalidChildren(LoggerInterface $logger)
35
    {
36
        // "head" element must contain only metadata content elements.
37
        // "head" element must contain exactly one "title" element.
38
        // "head" element must contain either 0 or 1 "base" element.
39
        $titleCount = 0;
40
        $baseCount = 0;
41
        foreach ($this->children as $child) {
42
            if ($child instanceof NonParticipating) {
43
                continue;
44
            }
45
46
            if (!$child instanceof MetadataContent) {
47
                $logger->debug('Removing ' . $child . '. Only children of metadata content allowed.');
48
                $this->removeChild($child);
49
50
                continue;
51
            }
52
53
            if ($child instanceof Title) {
54
                ++$titleCount;
55
                if ($titleCount > 1) {
56
                    $logger->debug('Removing ' . $child . '. Only one "title" element allowed.');
57
                    $this->removeChild($child);
58
59
                    continue;
60
                }
61
            } elseif ($child instanceof Base) {
62
                ++$baseCount;
63
                if ($baseCount > 1) {
64
                    $logger->debug('Removing ' . $child . '. Maximum one "base" element allowed.');
65
66
                    $this->removeChild($child);
67
68
                    continue;
69
                }
70
            }
71
        }
72
    }
73
74
    protected function removeInvalidSelf(LoggerInterface $logger)
75
    {

src/Tokens/Elements/Html.php 1 location

@@ 76-111 (lines=36) @@
73
        }
74
    }
75
76
    protected function removeInvalidChildren(LoggerInterface $logger)
77
    {
78
        $bodyCount = 0;
79
        $headCount = 0;
80
        foreach ($this->children as $key => $child) {
81
            if ($child instanceof NonParticipating) {
82
                continue;
83
            }
84
85
            // Check for HEAD and BODY
86
            if ($child instanceof Head) {
87
                ++$headCount;
88
89
                // Remove extraneous HEAD elements.
90
                if ($headCount > 1) {
91
                    $logger->debug('Removing ' . $child . '. Only one "head" element allowed.');
92
                    $this->removeChild($child);
93
94
                    continue;
95
                }
96
            } elseif ($child instanceof Body) {
97
                ++$bodyCount;
98
99
                // Remove extraneous BODY elements.
100
                if ($bodyCount > 1) {
101
                    $logger->debug('Removing ' . $child . '. Only one "body" element allowed.');
102
                    $this->removeChild($child);
103
104
                    continue;
105
                }
106
            } else {
107
                $logger->debug('Removing ' . $child . '. Only "head" or "body" elements are allowed as "html" element children.');
108
                $this->removeChild($child);
109
            }
110
        }
111
    }
112
113
    protected function removeInvalidSelf(LoggerInterface $logger)
114
    {