Completed
Push — master ( e0ac7a...8eddfc )
by Kevin
03:21
created

Dt::doClean()   C

Complexity

Conditions 12
Paths 3

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 12

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
dl 0
loc 38
ccs 25
cts 25
cp 1
rs 5.1612
cc 12
eloc 22
nc 3
nop 1
crap 12

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\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\HeadingContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\SectioningContent;
9
use Groundskeeper\Tokens\Token;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "dt" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-dt-element
16
 */
17
class Dt extends OpenElement
18
{
19 4
    protected function doClean(LoggerInterface $logger)
20
    {
21 4
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
22
            // Must be child of "dl" element.
23 4
            $parent = $this->getParent();
24 4
            if ($parent !== null &&
25 4
                $parent->getName() != 'dl') {
26 1
                $logger->debug('Element "dt" must be a child of a "dl" element.');
27
28 1
                return false;
29
            }
30
31
            // No "header", "footer", sectioning content, or heading content descendants.
32 3
            foreach ($this->children as $child) {
33 3
                if ($child->getType() == Token::COMMENT ||
34 3
                    $child->getType() == Token::TEXT) {
35 3
                    continue;
36
                }
37
38 1
                if ($child->getType() != Token::ELEMENT) {
39 1
                    $logger->debug('Removing ' . $child . '. Element "dt" cannot contain "header", "footer", section content, or heading content elements.');
40 1
                    $this->removeChild($child);
41
42 1
                    continue;
43
                }
44
45 1
                if ($child->getName() == 'header' ||
46 1
                    $child->getName() == 'footer' ||
47 1
                    $child instanceof SectioningContent ||
48 1
                    $child instanceof HeadingContent) {
49 1
                    $logger->debug('Removing ' . $child . '. No "header", "footer", and sectioning content, or heading content elements allowed as children of "dt" element.');
50 1
                    $this->removeChild($child);
51 1
                }
52 3
            }
53 3
        }
54
55 4
        return true;
56
    }
57
}
58