Completed
Push — master ( 1d4343...278efa )
by Kevin
04:08
created

Optgroup   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 31.71 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 13
loc 41
ccs 23
cts 23
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 12 1
B removeInvalidChildren() 13 13 5
A removeInvalidSelf() 0 11 3

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\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
9
use Groundskeeper\Tokens\NonParticipating;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "optgroup" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/forms.html#the-optgroup-element
16
 */
17
class Optgroup extends OpenElement
18
{
19 3
    protected function getAllowedAttributes()
20
    {
21
        $optgroupAllowedAttributes = array(
22 3
            '/^disabled$/i' => Attribute::BOOL,
23
            '/^label$/i' => Attribute::CS_STRING
24 3
        );
25
26 3
        return array_merge(
27 3
            $optgroupAllowedAttributes,
28 3
            parent::getAllowedAttributes()
29 3
        );
30
    }
31
32 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...
33
    {
34 2
        foreach ($this->children as $child) {
35 2
            if ($child instanceof NonParticipating ||
36 2
                $child instanceof Option ||
37 2
                $child instanceof ScriptSupporting) {
38 1
                continue;
39
            }
40
41 1
            $logger->debug('Removing ' . $child . '. Only "option" and script supporting elements allowed as children of a "optgroup" element.');
42 1
            $this->removeChild($child);
43 2
        }
44 2
    }
45
46 3
    protected function removeInvalidSelf(LoggerInterface $logger)
47
    {
48 3
        $parent = $this->getParent();
49 3
        if ($parent !== null && !$parent instanceof Select) {
50 1
            $logger->debug('Removing ' . $this . '. Only "select" element allowed as parent of "optgroup" element.');
51
52 1
            return true;
53
        }
54
55 2
        return false;
56
    }
57
}
58