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

Dt   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 4
Bugs 2 Features 2
Metric Value
wmc 9
c 4
b 2
f 2
lcom 1
cbo 2
dl 0
loc 30
ccs 15
cts 18
cp 0.8333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B removeInvalidChildren() 0 13 6
A removeInvalidSelf() 0 13 3
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