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

Ul::doClean()   C

Complexity

Conditions 7
Paths 2

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

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