Source::removeInvalidSelf()   A
last analyzed

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 0
Metric Value
dl 15
loc 15
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
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 View Code Duplication
class Source extends ClosedElement
0 ignored issues
show
Duplication introduced by
This class 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...
16
{
17 3
    protected function getAllowedAttributes()
18
    {
19
        $sourceAllowedAttributes = array(
20 3
            '/^src$/i' => Attribute::URI,
21
            '/^type$/i' => Attribute::CS_STRING,
22
            '/^srcset$/i' => Attribute::CS_STRING,
23
            '/^sizes$/i' => Attribute::CS_STRING,
24
            '/^media$/i' => Attribute::CS_STRING
25
        );
26
27 3
        return array_merge(
28 3
            $sourceAllowedAttributes,
29 3
            parent::getAllowedAttributes()
30
        );
31
    }
32
33 4
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
34
    {
35
        // Child of "picture" element.
36
        // Child of media element.
37 4
        $parent = $this->getParent();
38 4
        if ($parent !== null &&
39 4
            !$parent instanceof Picture &&
40 4
            !$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 3
        return false;
47
    }
48
}
49