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

Source::doClean()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

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