Completed
Push — master ( 817727...d8e3ee )
by Kevin
03:58
created

Tr::removeInvalidChildren()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 8.8571
cc 6
eloc 9
nc 3
nop 1
crap 6
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\OpenElement;
7
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
8
use Groundskeeper\Tokens\NonParticipating;
9
use Groundskeeper\Tokens\Token;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "tr" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-tr-element
16
 */
17
class Tr extends OpenElement
18
{
19 3
    protected function removeInvalidChildren(LoggerInterface $logger)
20
    {
21
        // Children can be "td", "th", and script supporting elements.
22 3
        foreach ($this->children as $child) {
23 3
            if ($child instanceof NonParticipating ||
24 2
                $child instanceof Td ||
25 2
                $child instanceof Th ||
26 3
                $child instanceof ScriptSupporting) {
27 3
                continue;
28
            }
29
30 1
            $logger->debug('Removing ' . $child . '. Only "td", "th", and script supporting elements allowed as children of "tr" element.');
31 1
            $this->removeChild($child);
32 3
        }
33 3
    }
34
35 3
    protected function removeInvalidSelf(LoggerInterface $logger)
36
    {
37
        // "table" must be parent.
38 3
        $parent = $this->getParent();
39 3
        if ($parent !== null &&
40 3
            !$parent instanceof Thead &&
41 3
            !$parent instanceof Tbody &&
42 3
            !$parent instanceof Tfoot &&
43 3
            !$parent instanceof Table) {
44 1
            $logger->debug('Removing ' . $this . '. Must be a child of the "thead", "tbody", "tfoot", or "table" elements.');
45
46 1
            return true;
47
        }
48
49 3
        return false;
50
    }
51
}
52