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

Dl::doClean()   D

Complexity

Conditions 9
Paths 7

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 31
ccs 20
cts 20
cp 1
rs 4.909
cc 9
eloc 17
nc 7
nop 1
crap 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\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
9
use Groundskeeper\Tokens\Token;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "dl" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-dl-element
16
 */
17
class Dl extends OpenElement implements FlowContent
18
{
19 3
    protected function doClean(LoggerInterface $logger)
20
    {
21
        // Only "dd", "dt", and ScriptSupporting elements allowed.
22 3
        foreach ($this->children as $child) {
23 3
            if ($child->getType() == Token::COMMENT) {
24 1
                continue;
25
            }
26
27 3
            if ($child->getType() != Token::ELEMENT) {
28 1
                if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
29 1
                    $logger->debug('Removing ' . $child . '. Only elements "dd", "dt", and script supporting elements allowed as children of "dl" element.');
30 1
                    $this->removeChild($child);
31 1
                }
32
33 1
                continue;
34
            }
35
36 3
            if ($child->getName() == 'dd' ||
37 3
                $child->getName() == 'dt' ||
38 3
                $child instanceof ScriptSupporting) {
39 3
                continue;
40
            }
41
42 1
            if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
43 1
                $logger->debug('Removing ' . $child . '. Only elements "dd", "dt", and script supporting elements allowed as children of "dl" element.');
44 1
                $this->removeChild($child);
45 1
            }
46 3
        }
47
48 3
        return true;
49
    }
50
}
51