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

Dt   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 12
c 2
b 1
f 2
lcom 1
cbo 3
dl 0
loc 41
ccs 25
cts 25
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C doClean() 0 38 12
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