Completed
Push — master ( 9fbe45...817727 )
by Kevin
03:24
created

Thead::doClean()   D

Complexity

Conditions 9
Paths 3

Size

Total Lines 36
Code Lines 19

Duplication

Lines 36
Ratio 100 %

Code Coverage

Tests 21
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 36
loc 36
ccs 21
cts 21
cp 1
rs 4.909
cc 9
eloc 19
nc 3
nop 1
crap 9
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\Token;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * "thead" element
13
 *
14
 * https://html.spec.whatwg.org/multipage/semantics.html#the-thead-element
15
 */
16
class Thead extends OpenElement
17
{
18 3
    protected function removeInvalidChildren(LoggerInterface $logger)
19
    {
20
        // Children can be "tr" and script supporting elements.
21 3
        foreach ($this->children as $child) {
22 3
            if ($child->getType() == Token::COMMENT) {
23 1
                continue;
24
            }
25
26 3
            if ($child->getType() !== Token::ELEMENT) {
27 1
                $logger->debug('Removing ' . $child . '. Only elements allowed as children of "thead" element.');
28 1
                $this->removeChild($child);
29
30 1
                continue;
31
            }
32
33 2
            if ($child->getName() == 'tr' ||
34 2
                $child instanceof ScriptSupporting) {
35 1
                continue;
36
            }
37
38 1
            $logger->debug('Removing ' . $child . '. Only "tr" and script supporting elements allowed as children of "thead" element.');
39 1
            $this->removeChild($child);
40 3
        }
41 3
    }
42
43 4
    protected function removeInvalidSelf(LoggerInterface $logger)
44
    {
45
        // "table" must be parent.
46 4
        $parent = $this->getParent();
47 4
        if ($parent !== null && $parent->getName() != 'table') {
48 1
            $logger->debug($this . ' must be a child of the "table" element.');
49
50 1
            return true;
51
        }
52
53 3
        return false;
54
    }
55
}
56