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

Optgroup::removeInvalidChildren()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
ccs 0
cts 12
cp 0
rs 8.8571
cc 5
eloc 8
nc 3
nop 1
crap 30
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\Attribute;
6
use Groundskeeper\Tokens\Element;
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
 * "optgroup" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/forms.html#the-optgroup-element
16
 */
17
class Optgroup extends OpenElement
18
{
19
    protected function getAllowedAttributes()
20
    {
21
        $optgroupAllowedAttributes = array(
22
            '/^disabled$/i' => Attribute::BOOL,
23
            '/^label$/i' => Attribute::CS_STRING
24
        );
25
26
        return array_merge(
27
            $optgroupAllowedAttributes,
28
            parent::getAllowedAttributes()
29
        );
30
    }
31
32 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...
33
    {
34
        foreach ($this->children as $child) {
35
            if ($child instanceof NonParticipating ||
36
                $child instanceof Option ||
37
                $child instanceof ScriptSupporting) {
38
                continue;
39
            }
40
41
            $logger->debug('Removing ' . $child . '. Only "option" and script supporting elements allowed as children of a "optgroup" element.');
42
            $this->removeChild($child);
43
        }
44
    }
45
46
    protected function removeInvalidSelf(LoggerInterface $logger)
47
    {
48
        $parent = $this->getParent();
49
        if ($parent !== null && !$parent instanceof Select) {
50
            $logger->debug('Removing ' . $this . '. Only "select" element allowed as parent of "optgroup" element.');
51
52
            return true;
53
        }
54
55
        return false;
56
    }
57
}
58