Textarea   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 80.43 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 37
loc 46
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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