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

Dt::removeInvalidChildren()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.73

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 13
ccs 8
cts 11
cp 0.7272
rs 8.8571
cc 6
eloc 8
nc 3
nop 1
crap 6.73
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\HeadingContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\SectioningContent;
9
use Groundskeeper\Tokens\NonParticipating;
10
use Groundskeeper\Tokens\Text;
11
use Groundskeeper\Tokens\Token;
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * "dt" element
16
 *
17
 * https://html.spec.whatwg.org/multipage/semantics.html#the-dt-element
18
 */
19
class Dt extends OpenElement
20
{
21 2
    protected function removeInvalidChildren(LoggerInterface $logger)
22
    {
23
        // No "header", "footer", sectioning content, or heading content descendants.
24 2
        foreach ($this->children as $child) {
25 2
            if ($child instanceof Header ||
26 2
                $child instanceof Footer ||
27 2
                $child instanceof SectioningContent ||
28 2
                $child instanceof HeadingContent) {
29
                $logger->debug('Removing ' . $child . '. No "header", "footer", and sectioning content, or heading content elements allowed as children of "dt" element.');
30
                $this->removeChild($child);
0 ignored issues
show
Bug introduced by
It seems like $child can also be of type object<Groundskeeper\Tok...ntTypes\HeadingContent> or object<Groundskeeper\Tok...ypes\SectioningContent>; however, Groundskeeper\Tokens\Element::removeChild() does only seem to accept object<Groundskeeper\Tokens\Token>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
31
            }
32 2
        }
33 2
    }
34
35 3
    protected function removeInvalidSelf(LoggerInterface $logger)
36
    {
37
        // Must be child of "dl" element.
38 3
        $parent = $this->getParent();
39 3
        if ($parent !== null &&
40 3
            !$parent instanceof Dl) {
41 1
            $logger->debug('Removing ' . $this . '. Must be a child of a "dl" element.');
42
43 1
            return true;
44
        }
45
46 2
        return false;
47
    }
48
}
49