Button   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 78.05 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 32
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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

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\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