Completed
Push — master ( 559766...559d2f )
by Kevin
03:24
created

Button::getAllowedAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 22
loc 22
ccs 17
cts 17
cp 1
rs 9.2
cc 1
eloc 17
nc 1
nop 0
crap 1
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 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...
21
    {
22
        $buttonAllowedAttributes = array(
23 2
            '/^autofocus$/i' => Attribute::BOOL,
24 2
            '/^disabled$/i' => Attribute::BOOL,
25 2
            '/^form$/i' => Attribute::CS_STRING,
26 2
            '/^formaction$/i' => Attribute::URI,
27 2
            '/^formenctype$/i' => Attribute::CS_STRING,
28 2
            '/^formmethod$/i' => Attribute::CI_ENUM . '("","get","post","dialog"|"get")',
29 2
            '/^formnovalidate$/i' => Attribute::BOOL,
30 2
            '/^formtarget$/i' => Attribute::CS_STRING,
31 2
            '/^menu$/i' => Attribute::CS_STRING,
32 2
            '/^name$/i' => Attribute::CS_STRING,
33 2
            '/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")',
34
            '/^value$/i' => Attribute::CS_STRING
35 2
        );
36
37 2
        return array_merge(
38 2
            $buttonAllowedAttributes,
39 2
            parent::getAllowedAttributes()
40 2
        );
41
    }
42
43 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...
44
    {
45 2
        foreach ($this->children as $child) {
46 2
            if ($child instanceof InteractiveContent &&
47 2
                $child->isInteractiveContent()) {
48 1
                $logger->debug('Removing ' . $child . '. No interactive content inside a "button" element.');
49 1
                $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...
50 1
            }
51 2
        }
52 2
    }
53
54 1
    public function isInteractiveContent()
55
    {
56 1
        return true;
57
    }
58
}
59