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

Tr   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 12
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 35
ccs 21
cts 21
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B removeInvalidChildren() 0 15 6
B removeInvalidSelf() 0 16 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