Td::getAllowedAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\Attribute;
6
use Groundskeeper\Tokens\ElementTypes\OpenElement;
7
use Groundskeeper\Tokens\ElementTypes\SectioningRoot;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * "td" element
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-td-element
14
 */
15
class Td extends OpenElement implements SectioningRoot
16
{
17 1
    protected function getAllowedAttributes()
18
    {
19
        $tdAllowedAttributes = array(
20 1
            '/^colspan$/i' => Attribute::INT,
21
            '/^rowspan$/i' => Attribute::INT,
22
            '/^headers$/i' => Attribute::CS_STRING
23
        );
24
25 1
        return array_merge(
26 1
            $tdAllowedAttributes,
27 1
            parent::getAllowedAttributes()
28
        );
29
    }
30
31 4
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
32
    {
33
        // "tr" must be parent.
34 4
        $parent = $this->getParent();
35 4
        if ($parent !== null && !$parent instanceof Tr) {
36 1
            $logger->debug('Removing ' . $this . '. Must be a child of "tr" element.');
37
38 1
            return true;
39
        }
40
41 3
        return false;
42
    }
43
}
44