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

Button::removeInvalidChildren()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
cc 3
eloc 5
nc 3
nop 1
crap 12
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 Psr\Log\LoggerInterface;
12
13
/**
14
 * "button" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/forms.html#the-button-element
17
 */
18
class Button extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent
19
{
20 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...
21
    {
22
        $buttonAllowedAttributes = array(
23
            '/^autofocus$/i' => Attribute::BOOL,
24
            '/^disabled$/i' => Attribute::BOOL,
25
            '/^form$/i' => Attribute::CS_STRING,
26
            '/^formaction$/i' => Attribute::URI,
27
            '/^formenctype$/i' => Attribute::CS_STRING,
28
            '/^formmethod$/i' => Attribute::CI_ENUM . '("","get","post","dialog"|"get")',
29
            '/^formnovalidate$/i' => Attribute::BOOL,
30
            '/^formtarget$/i' => Attribute::CS_STRING,
31
            '/^menu$/i' => Attribute::CS_STRING,
32
            '/^name$/i' => Attribute::CS_STRING,
33
            '/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")',
34
            '/^value$/i' => Attribute::CS_STRING
35
        );
36
37
        return array_merge(
38
            $buttonAllowedAttributes,
39
            parent::getAllowedAttributes()
40
        );
41
    }
42
43 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...
44
    {
45
        foreach ($this->children as $child) {
46
            if ($child instanceof InteractiveContent) {
47
                $logger->debug('Removing ' . $child . '. No interactive content inside a "button" element.');
48
                $this->removeChild($child);
0 ignored issues
show
Documentation introduced by
$child is of type object<Groundskeeper\Tok...pes\InteractiveContent>, but the function expects a object<Groundskeeper\Tokens\Token>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
            }
50
        }
51
    }
52
53
    public function isInteractiveContent()
54
    {
55
        return true;
56
    }
57
}
58