Button::removeInvalidChildren()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 7
cts 7
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
crap 4
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 Psr\Log\LoggerInterface;
11
12
/**
13
 * "button" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/forms.html#the-button-element
16
 */
17
class Button extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent
18
{
19 2 View Code Duplication
    protected function getAllowedAttributes()
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...
20
    {
21
        $buttonAllowedAttributes = array(
22 2
            '/^autofocus$/i' => Attribute::BOOL,
23
            '/^disabled$/i' => Attribute::BOOL,
24
            '/^form$/i' => Attribute::CS_STRING,
25
            '/^formaction$/i' => Attribute::URI,
26
            '/^formenctype$/i' => Attribute::CS_STRING,
27
            '/^formmethod$/i' => Attribute::CI_ENUM . '("","get","post","dialog"|"get")',
28
            '/^formnovalidate$/i' => Attribute::BOOL,
29
            '/^formtarget$/i' => Attribute::CS_STRING,
30
            '/^menu$/i' => Attribute::CS_STRING,
31
            '/^name$/i' => Attribute::CS_STRING,
32
            '/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")',
33
            '/^value$/i' => Attribute::CS_STRING
34
        );
35
36 2
        return array_merge(
37 2
            $buttonAllowedAttributes,
38 2
            parent::getAllowedAttributes()
39
        );
40
    }
41
42 2 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...
43
    {
44 2
        foreach ($this->children as $child) {
45 2
            if ($child instanceof InteractiveContent &&
46 2
                $child->isInteractiveContent()) {
47 1
                $logger->debug('Removing ' . $child . '. No interactive content inside a "button" element.');
48 2
                $this->removeChild($child);
49
            }
50
        }
51 2
    }
52
53 1
    public function isInteractiveContent() : bool
54
    {
55 1
        return true;
56
    }
57
}
58