Completed
Push — master ( e0ac7a...8eddfc )
by Kevin
03:21
created

Audio::isInteractiveContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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\Token;
14
use Psr\Log\LoggerInterface;
15
16
/**
17
 * "audio" element
18
 *
19
 * https://html.spec.whatwg.org/multipage/semantics.html#the-audio-element
20
 */
21
class Audio extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent, InteractiveContent, TransparentElement
22
{
23
    protected function getAllowedAttributes()
24
    {
25
        $audioAllowedAttributes = array(
26
            '/^src$/i' => Element::ATTR_URI,
27
            '/^crossorigin$/i' => Element::ATTR_CS_STRING,
28
            '/^preload$/i' => Element::ATTR_CI_ENUM . '("","none","metadata","auto"|"")',
29
            '/^autoplay$/i' => Element::ATTR_BOOL,
30
            '/^mediagroup$/i' => Element::ATTR_CS_STRING,
31
            '/^loop$/i' => Element::ATTR_BOOL,
32
            '/^muted$/i' => Element::ATTR_BOOL,
33
            '/^controls$/i' => Element::ATTR_BOOL
34
        );
35
36
        return array_merge(
37
            $audioAllowedAttributes,
38
            parent::getAllowedAttributes()
39
        );
40
    }
41
42 View Code Duplication
    protected function doClean(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...
43
    {
44
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
45
            $hasSrc = $this->hasAttribute('src');
46
            foreach ($this->children as $child) {
47
                if ($child->getType() == Token::COMMENT) {
48
                    continue;
49
                }
50
51
                if ($child->getType() == Token::TEXT) {
52
                    continue;
53
                }
54
55
                if ($child->getType() !== Token::ELEMENT) {
56
                    $logger->debug('Removing ' . $child . '. Only elements allowed as children of "audio" element.');
57
                    $this->removeChild($child);
58
59
                    continue;
60
                }
61
62
                if (!$hasSrc && $child->getName() == 'source') {
63
                    continue;
64
                }
65
66
                if ($child->getName() == 'track') {
67
                    continue;
68
                }
69
70
                if ($child instanceof TransparentElement &&
71
                    $child->isTransparentElement()) {
72
                    continue;
73
                }
74
75
                $logger->debug('Removing ' . $child . '. Only "source", "track", and transparent elements allowed as children of "audio" element.');
76
                $this->removeChild($child);
77
            }
78
        }
79
80
        return true;
81
    }
82
83
    public function isInteractiveContent()
84
    {
85
        return $this->hasAttribute('controls');
86
    }
87
88
    public function isTransparentElement()
89
    {
90
        /// @todo Implement this.  Complicated checks involved.
91
        return true;
92
    }
93
}
94