Completed
Push — master ( d8e3ee...0777f1 )
by Kevin
03:18
created

Form   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 89.47%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 2
dl 11
loc 33
ccs 17
cts 19
cp 0.8947
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 18 1
A removeInvalidSelf() 11 11 2

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\Element;
6
use Groundskeeper\Tokens\ElementTypes\OpenElement;
7
use Psr\Log\LoggerInterface;
8
9
/**
10
 * "form" element
11
 *
12
 * https://html.spec.whatwg.org/multipage/forms.html#the-form-element
13
 */
14
class Form extends OpenElement
15
{
16 1
    protected function getAllowedAttributes()
17
    {
18
        $formAllowedAttributes = array(
19 1
            '/^accept-charset$/i' => Element::ATTR_CS_STRING,
20 1
            '/^action$/i' => Element::ATTR_URI,
21 1
            '/^autocomplete$/i' => Element::ATTR_CI_ENUM . '("","on","off")',
22 1
            '/^enctype$/i' => Element::ATTR_CS_STRING,
23 1
            '/^method$/i' => Element::ATTR_CI_ENUM . '("","get","post","dialog"|"get")',
24 1
            '/^name$/i' => Element::ATTR_CS_STRING,
25 1
            '/^novalidate$/i' => Element::ATTR_BOOL,
26
            '/^target$/i' => Element::ATTR_CS_STRING
27 1
        );
28
29 1
        return array_merge(
30 1
            $formAllowedAttributes,
31 1
            parent::getAllowedAttributes()
32 1
        );
33
    }
34
35 1 View Code Duplication
    protected function removeInvalidSelf(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...
36
    {
37 1
        $form = new self($this->configuration, 'form');
38 1
        if ($this->hasAncestor($form)) {
39
            $logger->debug('Removing ' . $this . '. Cannot be have a "form" element ancestor.');
40
41
            return true;
42
        }
43
44 1
        return false;
45
    }
46
}
47