Code Duplication    Length = 30-30 lines in 3 locations

src/Tokens/Elements/Tbody.php 1 location

@@ 15-44 (lines=30) @@
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-tbody-element
14
 */
15
class Tbody extends OpenElement
16
{
17
    protected function removeInvalidChildren(LoggerInterface $logger)
18
    {
19
        // Children can be "tr" and script supporting elements.
20
        foreach ($this->children as $child) {
21
            if ($child instanceof NonParticipating ||
22
                $child instanceof Tr ||
23
                $child instanceof ScriptSupporting) {
24
                continue;
25
            }
26
27
            $logger->debug('Removing ' . $child . '. Only "tr" and script supporting elements allowed as children of "tbody" element.');
28
            $this->removeChild($child);
29
        }
30
    }
31
32
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
33
    {
34
        // "table" must be parent.
35
        $parent = $this->getParent();
36
        if ($parent !== null && !$parent instanceof Table) {
37
            $logger->debug('Removing ' . $this . '. Must be a child of the "table" element.');
38
39
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45

src/Tokens/Elements/Thead.php 1 location

@@ 15-44 (lines=30) @@
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-thead-element
14
 */
15
class Thead extends OpenElement
16
{
17
    protected function removeInvalidChildren(LoggerInterface $logger)
18
    {
19
        // Children can be "tr" and script supporting elements.
20
        foreach ($this->children as $child) {
21
            if ($child instanceof NonParticipating ||
22
                $child instanceof Tr ||
23
                $child instanceof ScriptSupporting) {
24
                continue;
25
            }
26
27
            $logger->debug('Removing ' . $child . '. Only "tr" and script supporting elements allowed as children of "thead" element.');
28
            $this->removeChild($child);
29
        }
30
    }
31
32
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
33
    {
34
        // "table" must be parent.
35
        $parent = $this->getParent();
36
        if ($parent !== null && !$parent instanceof Table) {
37
            $logger->debug('Removing ' . $this . '. Must be a child of the "table" element.');
38
39
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45

src/Tokens/Elements/Tfoot.php 1 location

@@ 15-44 (lines=30) @@
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-tfoot-element
14
 */
15
class Tfoot extends OpenElement
16
{
17
    protected function removeInvalidChildren(LoggerInterface $logger)
18
    {
19
        // Children can be "tr" and script supporting elements.
20
        foreach ($this->children as $child) {
21
            if ($child instanceof NonParticipating ||
22
                $child instanceof Tr ||
23
                $child instanceof ScriptSupporting) {
24
                continue;
25
            }
26
27
            $logger->debug('Removing ' . $child . '. Only "tr" and script supporting elements allowed as children of "tfoot" element.');
28
            $this->removeChild($child);
29
        }
30
    }
31
32
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
33
    {
34
        // "table" must be parent.
35
        $parent = $this->getParent();
36
        if ($parent !== null && $parent->getName() !== 'table') {
37
            $logger->debug($this . ' must be a child of the "table" element.');
38
39
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45