Completed
Push — master ( 45904d...9fbe45 )
by Kevin
03:18
created

Menu::getAllowedAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\Element;
7
use Groundskeeper\Tokens\ElementTypes\FlowContent;
8
use Groundskeeper\Tokens\ElementTypes\OpenElement;
9
use Groundskeeper\Tokens\Token;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "menu" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-menu-element
16
 */
17
class Menu extends OpenElement implements FlowContent
18
{
19 1
    protected function getAllowedAttributes()
20
    {
21
        $menuAllowedAttributes = array(
22 1
            '/^type$/i' => Element::ATTR_CI_ENUM . '("","context","toolbar"|"context")',
23
            '/^label$/i' => Element::ATTR_CS_STRING
24 1
        );
25
26 1
        return array_merge(
27 1
            $menuAllowedAttributes,
28 1
            parent::getAllowedAttributes()
29 1
        );
30
    }
31
32 1
    protected function doClean(LoggerInterface $logger)
33
    {
34 1
        if (!$this->hasAttribute('type')) {
35 1
            $logger->debug('Adding the default type attribute for the "menu" element.');
36 1
            $this->addAttribute('type', 'context');
37 1
        }
38
39 1
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
40
            // Only "li" and ScriptSupporting elements allowed.
41 1
            foreach ($this->children as $child) {
42 1
                if ($child->getType() == Token::COMMENT) {
43
                    continue;
44
                }
45
46 1
                if ($child->getType() != Token::ELEMENT) {
47
                    $logger->debug('Removing ' . $child . '. Only elements "li", "menuitem", "hr", "menu", and script supporting elements allowed as children of "menu" element.');
48
                    $this->removeChild($child);
49
50
                    continue;
51
                }
52
53
                /// @todo
54 1
            }
55 1
        }
56
57 1
        return true;
58
    }
59
}
60