Completed
Push — master ( 559766...559d2f )
by Kevin
03:24
created

Video::removeInvalidChildren()   C

Complexity

Conditions 9
Paths 5

Size

Total Lines 23
Code Lines 14

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 15.7829

Importance

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