Completed
Push — master ( 0490e0...5154b1 )
by Kevin
03:30
created

Select   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 34.15 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 14
loc 41
ccs 26
cts 26
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 18 1
B removeInvalidChildren() 14 14 6
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 Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
12
use Groundskeeper\Tokens\NonParticipating;
13
use Psr\Log\LoggerInterface;
14
15
/**
16
 * "select" element
17
 *
18
 * https://html.spec.whatwg.org/multipage/forms.html#the-select-element
19
 */
20
class Select extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent
21
{
22 1
    protected function getAllowedAttributes()
23
    {
24
        $selectAllowedAttributes = array(
25 1
            '/^autocomplete$/i' => Attribute::CS_STRING,
26 1
            '/^autofocus$/i' => Attribute::BOOL,
27 1
            '/^disabled$/i' => Attribute::BOOL,
28 1
            '/^form$/i' => Attribute::CS_STRING,
29 1
            '/^multiple$/i' => Attribute::BOOL,
30 1
            '/^name$/i' => Attribute::CS_STRING,
31 1
            '/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")',
32
            '/^value$/i' => Attribute::CS_STRING
33 1
        );
34
35 1
        return array_merge(
36 1
            $selectAllowedAttributes,
37 1
            parent::getAllowedAttributes()
38 1
        );
39
    }
40
41 3 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...
42
    {
43 3
        foreach ($this->children as $child) {
44 3
            if ($child instanceof NonParticipating ||
45 3
                $child instanceof Option ||
46 2
                $child instanceof Optgroup ||
47 3
                $child instanceof ScriptSupporting) {
48 3
                continue;
49
            }
50
51 1
            $logger->debug('Removing ' . $child . '. Only "option, "optgroup", and script supporting elements allowed as children of a "select" element.');
52 1
            $this->removeChild($child);
53 3
        }
54 3
    }
55
56 1
    public function isInteractiveContent()
57
    {
58 1
        return true;
59
    }
60
}
61