Completed
Push — master ( 559d2f...0490e0 )
by Kevin
03:29
created

Audio::removeInvalidChildren()   D

Complexity

Conditions 9
Paths 6

Size

Total Lines 26
Code Lines 15

Duplication

Lines 26
Ratio 100 %

Code Coverage

Tests 17
CRAP Score 9

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 26
loc 26
ccs 17
cts 17
cp 1
rs 4.909
cc 9
eloc 15
nc 6
nop 1
crap 9
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\MediaElement;
11
use Groundskeeper\Tokens\ElementTypes\OpenElement;
12
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
13
use Groundskeeper\Tokens\ElementTypes\TransparentElement;
14
use Groundskeeper\Tokens\Text;
15
use Psr\Log\LoggerInterface;
16
17
/**
18
 * "audio" element
19
 *
20
 * https://html.spec.whatwg.org/multipage/semantics.html#the-audio-element
21
 */
22
class Audio extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent, InteractiveContent, TransparentElement, MediaElement
23
{
24 1
    protected function getAllowedAttributes()
25
    {
26
        $audioAllowedAttributes = array(
27 1
            '/^src$/i' => Attribute::URI,
28 1
            '/^crossorigin$/i' => Attribute::CS_STRING,
29 1
            '/^preload$/i' => Attribute::CI_ENUM . '("","none","metadata","auto"|"")',
30 1
            '/^autoplay$/i' => Attribute::BOOL,
31 1
            '/^mediagroup$/i' => Attribute::CS_STRING,
32 1
            '/^loop$/i' => Attribute::BOOL,
33 1
            '/^muted$/i' => Attribute::BOOL,
34
            '/^controls$/i' => Attribute::BOOL
35 1
        );
36
37 1
        return array_merge(
38 1
            $audioAllowedAttributes,
39 1
            parent::getAllowedAttributes()
40 1
        );
41
    }
42
43 3 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...
44
    {
45 3
        $hasSrc = $this->hasAttribute('src');
46 3
        foreach ($this->children as $child) {
47 3
            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...
48 3
                $child instanceof Text) {
49 1
                continue;
50
            }
51
52 3
            if (!$hasSrc && $child instanceof Source) {
53 1
                continue;
54
            }
55
56 2
            if ($child instanceof Track) {
57 1
                continue;
58
            }
59
60 2
            if ($child instanceof TransparentElement &&
61 2
                $child->isTransparentElement()) {
62 1
                continue;
63
            }
64
65 1
            $logger->debug('Removing ' . $child . '. Only text, "source", "track", and transparent elements allowed as children of "audio" element.');
66 1
            $this->removeChild($child);
67 3
        }
68 3
    }
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