Select::removeInvalidChildren()   B
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 10
cts 10
cp 1
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 9
nc 3
nop 1
crap 6
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\InteractiveContent;
8
use Groundskeeper\Tokens\ElementTypes\OpenElement;
9
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
10
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
11
use Groundskeeper\Tokens\NonParticipating;
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * "select" element
16
 *
17
 * https://html.spec.whatwg.org/multipage/forms.html#the-select-element
18
 */
19
class Select extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent
20
{
21 1
    protected function getAllowedAttributes()
22
    {
23
        $selectAllowedAttributes = array(
24 1
            '/^autocomplete$/i' => Attribute::CS_STRING,
25
            '/^autofocus$/i' => Attribute::BOOL,
26
            '/^disabled$/i' => Attribute::BOOL,
27
            '/^form$/i' => Attribute::CS_STRING,
28
            '/^multiple$/i' => Attribute::BOOL,
29
            '/^name$/i' => Attribute::CS_STRING,
30
            '/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")',
31
            '/^value$/i' => Attribute::CS_STRING
32
        );
33
34 1
        return array_merge(
35 1
            $selectAllowedAttributes,
36 1
            parent::getAllowedAttributes()
37
        );
38
    }
39
40 5 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...
41
    {
42 5
        foreach ($this->children as $child) {
43 5
            if ($child instanceof NonParticipating ||
44 5
                $child instanceof Option ||
45 3
                $child instanceof Optgroup ||
46 5
                $child instanceof ScriptSupporting) {
47 5
                continue;
48
            }
49
50 1
            $logger->debug('Removing ' . $child . '. Only "option, "optgroup", and script supporting elements allowed as children of a "select" element.');
51 1
            $this->removeChild($child);
52
        }
53 5
    }
54
55 1
    public function isInteractiveContent() : bool
56
    {
57 1
        return true;
58
    }
59
}
60