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

Button   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 77.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 31
loc 40
ccs 0
cts 34
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 22 22 1
A removeInvalidChildren() 9 9 3
A isInteractiveContent() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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