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

Video   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 59
Duplicated Lines 74.58 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 2
Metric Value
wmc 12
c 5
b 2
f 2
lcom 1
cbo 3
dl 44
loc 59
ccs 36
cts 36
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 21 21 1
C removeInvalidChildren() 23 23 9
A isInteractiveContent() 0 4 1
A isTransparentElement() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\NonParticipating;
15
use Groundskeeper\Tokens\Text;
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, MediaElement
24
{
25 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...
26
    {
27
        $videoAllowedAttributes = array(
28 1
            '/^src$/i' => Attribute::URI,
29 1
            '/^crossorigin$/i' => Attribute::CS_STRING,
30 1
            '/^poster$/i' => Attribute::URI,
31 1
            '/^preload$/i' => Attribute::CI_ENUM . '("","none","metadata","auto"|"")',
32 1
            '/^autoplay$/i' => Attribute::BOOL,
33 1
            '/^mediagroup$/i' => Attribute::CS_STRING,
34 1
            '/^loop$/i' => Attribute::BOOL,
35 1
            '/^muted$/i' => Attribute::BOOL,
36 1
            '/^controls$/i' => Attribute::BOOL,
37 1
            '/^width$/i' => Attribute::INT,
38
            '/^height$/i' => Attribute::INT
39 1
        );
40
41 1
        return array_merge(
42 1
            $videoAllowedAttributes,
43 1
            parent::getAllowedAttributes()
44 1
        );
45
    }
46
47 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...
48
    {
49 3
        $hasSrc = $this->hasAttribute('src');
50 3
        foreach ($this->children as $child) {
51 3
            if ($child instanceof NonParticipating ||
52 3
                $child instanceof Text ||
53 3
                $child instanceof Track) {
54 2
                continue;
55
            }
56
57 3
            if (!$hasSrc && $child instanceof Source) {
58 1
                continue;
59
            }
60
61 2
            if ($child instanceof TransparentElement &&
62 2
                $child->isTransparentElement()) {
63 1
                continue;
64
            }
65
66 1
            $logger->debug('Removing ' . $child . '. Only "source", "track", and transparent elements allowed as children of "video" element.');
67 1
            $this->removeChild($child);
68 3
        }
69 3
    }
70
71 1
    public function isInteractiveContent()
72
    {
73 1
        return $this->hasAttribute('controls');
74
    }
75
76 1
    public function isTransparentElement()
77
    {
78
        /// @todo Implement this.  Complicated checks involved.
79 1
        return true;
80
    }
81
}
82