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

Ul   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 3
Metric Value
wmc 7
c 3
b 1
f 3
lcom 1
cbo 3
dl 0
loc 30
ccs 16
cts 16
cp 1
rs 10

1 Method

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