Completed
Push — master ( 45904d...9fbe45 )
by Kevin
03:18
created

Tbody::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
 * "tbody" element
13
 *
14
 * https://html.spec.whatwg.org/multipage/semantics.html#the-tbody-element
15
 */
16 View Code Duplication
class Tbody extends OpenElement
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18 4
    protected function doClean(LoggerInterface $logger)
19
    {
20 4
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
21
            // "table" must be parent.
22 4
            $parent = $this->getParent();
23 4
            if ($parent !== null && $parent->getName() != 'table') {
24 1
                $logger->debug('Element "tbody" must be a child of the "table" element.');
25
26 1
                return false;
27
            }
28
29
            // Children can be "tr" and script supporting elements.
30 3
            foreach ($this->children as $child) {
31 3
                if ($child->getType() == Token::COMMENT) {
32 1
                    continue;
33
                }
34
35 3
                if ($child->getType() !== Token::ELEMENT) {
36 1
                    $logger->debug('Removing ' . $child . '. Only elements allowed as children of "tbody" element.');
37 1
                    $this->removeChild($child);
38
39 1
                    continue;
40
                }
41
42 2
                if ($child->getName() == 'tr' ||
43 2
                    $child instanceof ScriptSupporting) {
44 1
                    continue;
45
                }
46
47 1
                $logger->debug('Removing ' . $child . '. Only "tr" and script supporting elements allowed as children of "tbody" element.');
48 1
                $this->removeChild($child);
49 3
            }
50 3
        }
51
52 4
        return true;
53
    }
54
}
55