Completed
Push — master ( 9fbe45...817727 )
by Kevin
03:24
created

Track::getAllowedAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 15
ccs 0
cts 14
cp 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\ClosedElement;
7
use Psr\Log\LoggerInterface;
8
9
/**
10
 * "track" element
11
 *
12
 * https://html.spec.whatwg.org/multipage/semantics.html#the-track-element
13
 */
14
class Track extends ClosedElement
15
{
16
    protected function getAllowedAttributes()
17
    {
18
        $trackAllowedAttributes = array(
19
            '/^kind$/i' => Element::ATTR_CS_STRING,
20
            '/^src$/i' => Element::ATTR_URI,
21
            '/^srclang$/i' => Element::ATTR_CS_STRING,
22
            '/^label$/i' => Element::ATTR_CS_STRING,
23
            '/^default$/i' => Element::ATTR_BOOL
24
        );
25
26
        return array_merge(
27
            $trackAllowedAttributes,
28
            parent::getAllowedAttributes()
29
        );
30
    }
31
32
    protected function removeInvalidSelf(LoggerInterface $logger)
33
    {
34
        // Must be child of "object" element.
35
        $parent = $this->getParent();
36
        if ($parent !== null &&
37
            $parent->getName() !== 'video' &&
38
            $parent->getName() !== 'audio') {
39
            $logger->debug($this . ' must be a child of "video" or "audio" element.');
40
41
            return true;
42
        }
43
44
        return false;
45
    }
46
}
47