Completed
Push — master ( 9fbe45...817727 )
by Kevin
03:24
created

Address::removeInvalidChildren()   C

Complexity

Conditions 8
Paths 6

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
ccs 20
cts 20
cp 1
rs 5.3846
cc 8
eloc 17
nc 6
nop 1
crap 8
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\FlowContent;
7
use Groundskeeper\Tokens\ElementTypes\HeadingContent;
8
use Groundskeeper\Tokens\ElementTypes\OpenElement;
9
use Groundskeeper\Tokens\ElementTypes\SectioningContent;
10
use Groundskeeper\Tokens\Token;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * "address" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/semantics.html#the-address-element
17
 */
18
class Address extends OpenElement implements FlowContent
19
{
20 3
    protected function removeInvalidChildren(LoggerInterface $logger)
21
    {
22
        // No HeadingContent descendants
23
        // No SectioningContent descendants
24
        // No "header", "footer", or "address" element descendants.
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25 3
        foreach ($this->children as $child) {
26 3
            if ($child instanceof HeadingContent) {
27 1
                $logger->debug('Removing ' . $child . '. Heading Content elements not allowed as "address" element child.');
28 1
                $this->removeChild($child);
0 ignored issues
show
Documentation introduced by
$child is of type object<Groundskeeper\Tok...ntTypes\HeadingContent>, but the function expects a object<Groundskeeper\Tokens\Token>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
30 1
                continue;
31
            }
32
33 3
            if ($child instanceof SectioningContent) {
34 1
                $logger->debug('Removing ' . $child . '. Sectioning Content elements not allowed as "address" element child.');
35 1
                $this->removeChild($child);
0 ignored issues
show
Documentation introduced by
$child is of type object<Groundskeeper\Tok...ypes\SectioningContent>, but the function expects a object<Groundskeeper\Tokens\Token>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
37 1
                continue;
38
            }
39
40 3
            if ($child->getType() == Token::ELEMENT) {
41 2
                if ($child->getName() == 'header' ||
42 2
                    $child->getName() == 'footer' ||
43 2
                    $child->getName() == 'address') {
44 1
                    $logger->debug('Removing ' . $child . '. Elements "header", "footer", and "address" not allowed as "address" element child.');
45 1
                    $this->removeChild($child);
46
47 1
                    continue;
48
                }
49 1
            }
50 3
        }
51 3
    }
52
}
53