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

Source::removeInvalidSelf()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 15
loc 15
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 8
nc 2
nop 1
crap 4
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\Attribute;
6
use Groundskeeper\Tokens\ElementTypes\ClosedElement;
7
use Groundskeeper\Tokens\ElementTypes\MediaElement;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * "source" element
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-source-element
14
 */
15
class Source extends ClosedElement
16
{
17 2
    protected function getAllowedAttributes()
18
    {
19
        $sourceAllowedAttributes = array(
20 2
            '/^src$/i' => Attribute::URI,
21 2
            '/^type$/i' => Attribute::CS_STRING,
22 2
            '/^srcset$/i' => Attribute::CS_STRING,
23 2
            '/^sizes$/i' => Attribute::CS_STRING,
24
            '/^media$/i' => Attribute::CS_STRING
25 2
        );
26
27 2
        return array_merge(
28 2
            $sourceAllowedAttributes,
29 2
            parent::getAllowedAttributes()
30 2
        );
31
    }
32
33 3 View Code Duplication
    protected function removeInvalidSelf(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...
34
    {
35
        // Child of "picture" element.
36
        // Child of media element.
37 3
        $parent = $this->getParent();
38 3
        if ($parent !== null &&
39 3
            !$parent instanceof Picture &&
40 3
            !$parent instanceof MediaElement) {
41 1
            $logger->debug('Removing ' . $this . ' must be a child of "picture" element or a media element.');
42
43 1
            return true;
44
        }
45
46 2
        return false;
47
    }
48
}
49