Completed
Push — master ( 91ab9a...64950e )
by Kevin
04:15
created

Select::removeInvalidChildren()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 6.73

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
ccs 8
cts 11
cp 0.7272
rs 8.8571
cc 6
eloc 9
nc 3
nop 1
crap 6.73
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\Attribute;
6
use Groundskeeper\Tokens\Element;
7
use Groundskeeper\Tokens\ElementTypes\FlowContent;
8
use Groundskeeper\Tokens\ElementTypes\InteractiveContent;
9
use Groundskeeper\Tokens\ElementTypes\OpenElement;
10
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
11
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
12
use Groundskeeper\Tokens\NonParticipating;
13
use Psr\Log\LoggerInterface;
14
15
/**
16
 * "select" element
17
 *
18
 * https://html.spec.whatwg.org/multipage/forms.html#the-select-element
19
 */
20
class Select extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent
21
{
22 1
    protected function getAllowedAttributes()
23
    {
24
        $selectAllowedAttributes = array(
25 1
            '/^autocomplete$/i' => Attribute::CS_STRING,
26 1
            '/^autofocus$/i' => Attribute::BOOL,
27 1
            '/^disabled$/i' => Attribute::BOOL,
28 1
            '/^form$/i' => Attribute::CS_STRING,
29 1
            '/^multiple$/i' => Attribute::BOOL,
30 1
            '/^name$/i' => Attribute::CS_STRING,
31 1
            '/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")',
32
            '/^value$/i' => Attribute::CS_STRING
33 1
        );
34
35 1
        return array_merge(
36 1
            $selectAllowedAttributes,
37 1
            parent::getAllowedAttributes()
38 1
        );
39
    }
40
41 1 View Code Duplication
    protected function removeInvalidChildren(LoggerInterface $logger)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43 1
        foreach ($this->children as $child) {
44 1
            if ($child instanceof NonParticipating ||
45 1
                $child instanceof Option ||
46
                $child instanceof Optgroup ||
47 1
                $child instanceof ScriptSupporting) {
48 1
                continue;
49
            }
50
51
            $logger->debug('Removing ' . $child . '. Only "option, "optgroup", and script supporting elements allowed as children of a "select" element.');
52
            $this->removeChild($child);
53 1
        }
54 1
    }
55
56
    public function isInteractiveContent()
57
    {
58
        return true;
59
    }
60
}
61