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

Table::removeInvalidChildren()   B

Complexity

Conditions 10
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 10

Importance

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