Completed
Push — master ( 1ec99b...a17ead )
by Kevin
02:44
created

Hgroup::doClean()   C

Complexity

Conditions 13
Paths 7

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 182

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 37
ccs 0
cts 30
cp 0
rs 5.1234
cc 13
eloc 22
nc 7
nop 1
crap 182

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\ElementTypes\FlowContent;
6
use Groundskeeper\Tokens\ElementTypes\HeadingContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\Token;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * "hgroup" element
13
 */
14
class Hgroup extends OpenElement implements FlowContent, HeadingContent
15
{
16
    protected function doClean(LoggerInterface $logger = null)
17
    {
18
        // One or more "h1", "h2", "h3", "h4", "h5", "h6", and
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
19
        // "template" elements required.
20
        $headingContentElementCount = 0;
0 ignored issues
show
Unused Code introduced by
$headingContentElementCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
        foreach ($this->children as $child) {
22
            if ($child->getType() === Token::COMMENT) {
23
                continue;
24
            }
25
26
            if ($child->getType() !== Token::ELEMENT) {
27
                if ($logger !== null) {
28
                    $logger->debug('Removing ' . $child . '. Only "h1"-"h6" and "template" elements allowed as child of "hgroup" element.');
29
                }
30
31
                $this->removeChild($child);
32
                continue;
33
            }
34
35
            if ($child->getName() !== 'h1' &&
36
                $child->getName() !== 'h2' &&
37
                $child->getName() !== 'h3' &&
38
                $child->getName() !== 'h4' &&
39
                $child->getName() !== 'h5' &&
40
                $child->getName() !== 'h6' &&
41
                $child->getName() !== 'tempate') {
42
                if ($logger !== null) {
43
                    $logger->debug('Removing ' . $child . '. Only "h1"-"h6" and "template" elements allowed as child of "hgroup" element.');
44
                }
45
46
                $this->removeChild($child);
47
                continue;
48
            }
49
        }
50
51
        return true;
52
    }
53
}
54