Completed
Push — master ( 8eddfc...45904d )
by Kevin
03:22
created

Table   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 12
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 37
ccs 0
cts 26
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C doClean() 0 31 12
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
    protected function doClean(LoggerInterface $logger)
23
    {
24
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
25
            foreach ($this->children as $child) {
26
                if ($child->getType() == Token::COMMENT) {
27
                    continue;
28
                }
29
30
                if ($child->getType() !== Token::ELEMENT) {
31
                    $logger->debug('Removing ' . $child . '. Only elements allowed as children of "table" element.');
32
                    $this->removeChild($child);
33
34
                    continue;
35
                }
36
37
                if ($child->getName() == 'caption' ||
38
                    $child->getName() == 'colgroup' ||
39
                    $child->getName() == 'thead' ||
40
                    $child->getName() == 'tbody' ||
41
                    $child->getName() == 'tr' ||
42
                    $child->getName() == 'tfoot' ||
43
                    $child instanceof ScriptSupporting)
44
                    continue;
45
            }
46
47
            $logger->debug('Removing ' . $child . '. Only "caption", "colgroup", "thead", "tbody", "tr", "tfoot", and script supporting elements allowed as children of "table" element.');
0 ignored issues
show
Bug introduced by
The variable $child seems to be defined by a foreach iteration on line 25. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
48
            $this->removeChild($child);
49
        }
50
51
        return true;
52
    }
53
}
54