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

Audio::isInteractiveContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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\Text;
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 1
    protected function getAllowedAttributes()
24
    {
25
        $audioAllowedAttributes = array(
26 1
            '/^src$/i' => Attribute::URI,
27 1
            '/^crossorigin$/i' => Attribute::CS_STRING,
28 1
            '/^preload$/i' => Attribute::CI_ENUM . '("","none","metadata","auto"|"")',
29 1
            '/^autoplay$/i' => Attribute::BOOL,
30 1
            '/^mediagroup$/i' => Attribute::CS_STRING,
31 1
            '/^loop$/i' => Attribute::BOOL,
32 1
            '/^muted$/i' => Attribute::BOOL,
33
            '/^controls$/i' => Attribute::BOOL
34 1
        );
35
36 1
        return array_merge(
37 1
            $audioAllowedAttributes,
38 1
            parent::getAllowedAttributes()
39 1
        );
40
    }
41
42 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...
43
    {
44 1
        $hasSrc = $this->hasAttribute('src');
45 1
        foreach ($this->children as $child) {
46 1
            if ($child instanceof NonParticipanting ||
0 ignored issues
show
Bug introduced by
The class Groundskeeper\Tokens\Elements\NonParticipanting does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
47 1
                $child instanceof Text) {
48 1
                continue;
49
            }
50
51 1
            if (!$hasSrc && $child instanceof Source) {
52
                continue;
53
            }
54
55 1
            if ($child instanceof Track) {
56 1
                continue;
57
            }
58
59
            if ($child instanceof TransparentElement &&
60
                $child->isTransparentElement()) {
61
                continue;
62
            }
63
64
            $logger->debug('Removing ' . $child . '. Only text, "source", "track", and transparent elements allowed as children of "audio" element.');
65
            $this->removeChild($child);
66 1
        }
67 1
    }
68
69 1
    public function isInteractiveContent()
70
    {
71 1
        return $this->hasAttribute('controls');
72
    }
73
74 1
    public function isTransparentElement()
75
    {
76
        /// @todo Implement this.  Complicated checks involved.
77 1
        return true;
78
    }
79
}
80