Completed
Push — master ( 91ab9a...64950e )
by Kevin
04:15
created

Textarea::removeInvalidChildren()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
ccs 0
cts 11
cp 0
rs 9.2
cc 4
eloc 7
nc 3
nop 1
crap 20
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 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
            '/^autocomplete$/i' => Attribute::CS_STRING,
26
            '/^autofocus$/i' => Attribute::BOOL,
27
            '/^cols$/i' => Attribute::INT,
28
            '/^dirname$/i' => Attribute::CS_STRING,
29
            '/^disabled$/i' => Attribute::BOOL,
30
            '/^form$/i' => Attribute::CS_STRING,
31
            '/^inputmode$/i' => Attribute::CS_STRING,
32
            '/^maxlength$/i' => Attribute::CS_STRING,
33
            '/^minlength$/i' => Attribute::CS_STRING,
34
            '/^name$/i' => Attribute::CS_STRING,
35
            '/^placeholder$/i' => Attribute::CS_STRING,
36
            '/^readonly$/i' => Attribute::BOOL,
37
            '/^required$/i' => Attribute::BOOL,
38
            '/^rows$/i' => Attribute::INT,
39
            '/^wrap$/i' => Attribute::CI_ENUM . '("","soft","hard"|"soft")'
40
        );
41
42
        return array_merge(
43
            $textareaAllowedAttributes,
44
            parent::getAllowedAttributes()
45
        );
46
    }
47
48 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
        foreach ($this->children as $child) {
51
            if ($child instanceof NonParticipating ||
52
                $child instanceof Text) {
53
                continue;
54
            }
55
56
            $logger->debug('Removing ' . $child . '. Only text is allowed as children of a "textarea" element.');
57
            $this->removeChild($child);
58
        }
59
    }
60
61
    public function isInteractiveContent()
62
    {
63
        return true;
64
    }
65
}
66