Li   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 3
dl 0
loc 42
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 16 2
C removeInvalidSelf() 0 22 7
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\Attribute;
6
use Groundskeeper\Tokens\ElementTypes\OpenElement;
7
use Psr\Log\LoggerInterface;
8
9
/**
10
 * "li" element
11
 *
12
 * https://html.spec.whatwg.org/multipage/semantics.html#the-li-element
13
 */
14
class Li extends OpenElement
15
{
16 3
    protected function getAllowedAttributes()
17
    {
18
        // "value" attribute for "li" which are children of "ol" elements.
19 3
        if ($this->getParent() instanceof Ol) {
20
            $liAllowedAttributes = array(
21 1
                '/^value$/i' => Attribute::INT
22
            );
23
24 1
            return array_merge(
25 1
                $liAllowedAttributes,
26 1
                parent::getAllowedAttributes()
27
            );
28
        }
29
30 3
        return parent::getAllowedAttributes();
31
    }
32
33 6
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
34
    {
35
        // Only allowed:
36
        // Inside ol elements.
37
        // Inside ul elements.
38
        // Inside menu elements whose type attribute is in the toolbar state.
39 6
        $parent = $this->getParent();
40 6
        if ($parent === null || $parent instanceof Ol || $parent instanceof Ul) {
41 4
            return false;
42
        }
43
44 2
        if ($parent instanceof Menu && $parent->hasAttribute('type')) {
45 1
            $typeAttributeValue = $parent->getAttribute('type');
46 1
            if ($typeAttributeValue === 'toolbar') {
47 1
                return false;
48
            }
49
        }
50
51 2
        $logger->debug('Removing ' . $this . '. Only allowed inside the "li" element are "ol", "ul" and "menu[type=toolbar]" elements.');
52
53 2
        return true;
54
    }
55
}
56