Table::removeInvalidChildren()   B
last analyzed

Complexity

Conditions 10
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 10

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 14
cts 14
cp 1
rs 7.2765
c 0
b 0
f 0
cc 10
eloc 13
nc 3
nop 1
crap 10

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\Tokens\ElementTypes\FlowContent;
6
use Groundskeeper\Tokens\ElementTypes\OpenElement;
7
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
8
use Groundskeeper\Tokens\NonParticipating;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * "table" element
13
 *
14
 * https://html.spec.whatwg.org/multipage/semantics.html#the-table-element
15
 */
16
class Table extends OpenElement implements FlowContent
17
{
18
    /**
19
     * @todo Deal with validation of the order of child elements.
20
     */
21 6
    protected function removeInvalidChildren(LoggerInterface $logger)
22
    {
23 6
        foreach ($this->children as $child) {
24 6
            if ($child instanceof NonParticipating ||
25 6
                $child instanceof Caption ||
26 6
                $child instanceof Colgroup ||
27 6
                $child instanceof Thead ||
28 6
                $child instanceof Tbody ||
29 6
                $child instanceof Tr ||
30 4
                $child instanceof Tfoot ||
31 6
                $child instanceof ScriptSupporting) {
32 6
                continue;
33
            }
34
35 1
            $logger->debug('Removing ' . $child . '. Only "caption", "colgroup", "thead", "tbody", "tr", "tfoot", and script supporting elements allowed as children of "table" element.');
36 1
            $this->removeChild($child);
37
        }
38 6
    }
39
}
40