Ol::getAllowedAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\Attribute;
6
use Groundskeeper\Tokens\ElementTypes\FlowContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
9
use Groundskeeper\Tokens\NonParticipating;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "ol" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-ol-element
16
 */
17
class Ol extends OpenElement implements FlowContent
18
{
19 1
    protected function getAllowedAttributes()
20
    {
21
        $olAllowedAttributes = array(
22 1
            '/^reversed$/i' => Attribute::BOOL,
23
            '/^start$/i' => Attribute::INT,
24
            '/^type$/i' => Attribute::CS_STRING
25
        );
26
27 1
        return array_merge(
28 1
            $olAllowedAttributes,
29 1
            parent::getAllowedAttributes()
30
        );
31
    }
32
33 2
    protected function removeInvalidChildren(LoggerInterface $logger)
34
    {
35
        // Only "li" and ScriptSupporting elements allowed.
36 2
        foreach ($this->children as $child) {
37 2
            if ($child instanceof NonParticipating ||
38 2
                $child instanceof Li ||
39 2
                $child instanceof ScriptSupporting) {
40 2
                continue;
41
            }
42
43 1
            $logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ol" element.');
44 1
            $this->removeChild($child);
45
        }
46 2
    }
47
}
48