Completed
Push — master ( 817727...d8e3ee )
by Kevin
03:58
created

Li::getAllowedAttributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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