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

Table::removeInvalidChildren()   C

Complexity

Conditions 11
Paths 5

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
ccs 20
cts 20
cp 1
rs 5.2653
cc 11
eloc 18
nc 5
nop 1
crap 11

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\FlowContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
9
use Groundskeeper\Tokens\Token;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "table" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-table-element
16
 */
17
class Table extends OpenElement implements FlowContent
18
{
19
    /**
20
     * @todo Deal with validation of the order of child elements.
21
     */
22 5
    protected function removeInvalidChildren(LoggerInterface $logger)
23
    {
24 5
        foreach ($this->children as $child) {
25 5
            if ($child->getType() == Token::COMMENT) {
26 1
                continue;
27
            }
28
29 5
            if ($child->getType() !== Token::ELEMENT) {
30 1
                $logger->debug('Removing ' . $child . '. Only elements allowed as children of "table" element.');
31 1
                $this->removeChild($child);
32
33 1
                continue;
34
            }
35
36 5
            if ($child->getName() == 'caption' ||
37 5
                $child->getName() == 'colgroup' ||
38 5
                $child->getName() == 'thead' ||
39 5
                $child->getName() == 'tbody' ||
40 5
                $child->getName() == 'tr' ||
41 4
                $child->getName() == 'tfoot' ||
42 5
                $child instanceof ScriptSupporting) {
43 5
                continue;
44
            }
45
46 1
            $logger->debug('Removing ' . $child . '. Only "caption", "colgroup", "thead", "tbody", "tr", "tfoot", and script supporting elements allowed as children of "table" element.');
47 1
            $this->removeChild($child);
48 5
        }
49 5
    }
50
}
51