Completed
Push — master ( 817727...d8e3ee )
by Kevin
03:58
created

Video::removeInvalidChildren()   C

Complexity

Conditions 9
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 23
ccs 0
cts 20
cp 0
rs 5.8541
cc 9
eloc 14
nc 5
nop 1
crap 90
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\Element;
7
use Groundskeeper\Tokens\ElementTypes\EmbeddedContent;
8
use Groundskeeper\Tokens\ElementTypes\FlowContent;
9
use Groundskeeper\Tokens\ElementTypes\InteractiveContent;
10
use Groundskeeper\Tokens\ElementTypes\OpenElement;
11
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
12
use Groundskeeper\Tokens\ElementTypes\TransparentElement;
13
use Groundskeeper\Tokens\NonParticipating;
14
use Groundskeeper\Tokens\Text;
15
use Groundskeeper\Tokens\Token;
16
use Psr\Log\LoggerInterface;
17
18
/**
19
 * "video" element
20
 *
21
 * https://html.spec.whatwg.org/multipage/semantics.html#the-video-element
22
 */
23
class Video extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent, InteractiveContent, TransparentElement
24
{
25 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...
26
    {
27
        $videoAllowedAttributes = array(
28
            '/^src$/i' => Element::ATTR_URI,
29
            '/^crossorigin$/i' => Element::ATTR_CS_STRING,
30
            '/^poster$/i' => Element::ATTR_URI,
31
            '/^preload$/i' => Element::ATTR_CI_ENUM . '("","none","metadata","auto"|"")',
32
            '/^autoplay$/i' => Element::ATTR_BOOL,
33
            '/^mediagroup$/i' => Element::ATTR_CS_STRING,
34
            '/^loop$/i' => Element::ATTR_BOOL,
35
            '/^muted$/i' => Element::ATTR_BOOL,
36
            '/^controls$/i' => Element::ATTR_BOOL,
37
            '/^width$/i' => Element::ATTR_INT,
38
            '/^height$/i' => Element::ATTR_INT
39
        );
40
41
        return array_merge(
42
            $videoAllowedAttributes,
43
            parent::getAllowedAttributes()
44
        );
45
    }
46
47
    protected function removeInvalidChildren(LoggerInterface $logger)
48
    {
49
        $hasSrc = $this->hasAttribute('src');
50
        foreach ($this->children as $child) {
51
            if ($child instanceof NonParticipating ||
52
                $child instanceof Text ||
53
                $child instanceof Track) {
54
                continue;
55
            }
56
57
            if (!$hasSrc && $child instanceof Source) {
58
                continue;
59
            }
60
61
            if ($child instanceof TransparentElement &&
62
                $child->isTransparentElement()) {
63
                continue;
64
            }
65
66
            $logger->debug('Removing ' . $child . '. Only "source", "track", and transparent elements allowed as children of "video" element.');
67
            $this->removeChild($child);
68
        }
69
    }
70
71
    public function isInteractiveContent()
72
    {
73
        return $this->hasAttribute('controls');
74
    }
75
76
    public function isTransparentElement()
77
    {
78
        /// @todo Implement this.  Complicated checks involved.
79
        return true;
80
    }
81
}
82