Completed
Push — master ( 9f8b44...e0ac7a )
by Kevin
03:57
created

Address   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 2 Features 3
Metric Value
wmc 9
c 3
b 2
f 3
lcom 1
cbo 3
dl 0
loc 39
ccs 22
cts 22
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D doClean() 0 36 9
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 doClean(LoggerInterface $logger)
21
    {
22 3
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
23
            // No HeadingContent descendants
24
            // No SectioningContent descendants
25
            // 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...
26 3
            foreach ($this->children as $child) {
27 3
                if ($child instanceof HeadingContent) {
28 1
                    $logger->debug('Heading Content elements not allowed as "address" element child.');
29 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...
30
31 1
                    continue;
32
                }
33
34 3
                if ($child instanceof SectioningContent) {
35 1
                    $logger->debug('Sectioning Content elements not allowed as "address" element child.');
36 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...
37
38 1
                    continue;
39
                }
40
41 3
                if ($child->getType() == Token::ELEMENT) {
42 2
                    if ($child->getName() == 'header' ||
43 2
                        $child->getName() == 'footer' ||
44 2
                        $child->getName() == 'address') {
45 1
                        $logger->debug('Elements "header", "footer", and "address" not allowed as "address" element child.');
46 1
                        $this->removeChild($child);
47
48 1
                        continue;
49
                    }
50 1
                }
51 3
            }
52 3
        }
53
54 3
        return true;
55
    }
56
}
57