Completed
Push — master ( 64950e...559766 )
by Kevin
03:41
created

Textarea   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 80.43 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 37
loc 46
ccs 30
cts 32
cp 0.9375
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getAllowedAttributes() 25 25 1
A removeInvalidChildren() 12 12 4
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\NonParticipating;
12
use Groundskeeper\Tokens\Text;
13
use Psr\Log\LoggerInterface;
14
15
/**
16
 * "textarea" element
17
 *
18
 * https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element
19
 */
20
class Textarea extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent
21
{
22 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...
23
    {
24
        $textareaAllowedAttributes = array(
25 2
            '/^autocomplete$/i' => Attribute::CS_STRING,
26 2
            '/^autofocus$/i' => Attribute::BOOL,
27 2
            '/^cols$/i' => Attribute::INT,
28 2
            '/^dirname$/i' => Attribute::CS_STRING,
29 2
            '/^disabled$/i' => Attribute::BOOL,
30 2
            '/^form$/i' => Attribute::CS_STRING,
31 2
            '/^inputmode$/i' => Attribute::CS_STRING,
32 2
            '/^maxlength$/i' => Attribute::CS_STRING,
33 2
            '/^minlength$/i' => Attribute::CS_STRING,
34 2
            '/^name$/i' => Attribute::CS_STRING,
35 2
            '/^placeholder$/i' => Attribute::CS_STRING,
36 2
            '/^readonly$/i' => Attribute::BOOL,
37 2
            '/^required$/i' => Attribute::BOOL,
38 2
            '/^rows$/i' => Attribute::INT,
39 2
            '/^wrap$/i' => Attribute::CI_ENUM . '("","soft","hard"|"soft")'
40 2
        );
41
42 2
        return array_merge(
43 2
            $textareaAllowedAttributes,
44 2
            parent::getAllowedAttributes()
45 2
        );
46
    }
47
48 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...
49
    {
50 2
        foreach ($this->children as $child) {
51 2
            if ($child instanceof NonParticipating ||
52 2
                $child instanceof Text) {
53 2
                continue;
54
            }
55
56 1
            $logger->debug('Removing ' . $child . '. Only text is allowed as children of a "textarea" element.');
57 1
            $this->removeChild($child);
58 2
        }
59 2
    }
60
61
    public function isInteractiveContent()
62
    {
63
        return true;
64
    }
65
}
66