Completed
Push — master ( e0ac7a...8eddfc )
by Kevin
03:21
created

Source::doClean()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 8.8571
cc 5
eloc 9
nc 3
nop 1
crap 30
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
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 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...
18
    {
19
        $sourceAllowedAttributes = array(
20
            '/^src$/i' => Element::ATTR_URI,
21
            '/^type$/i' => Element::ATTR_CS_STRING,
22
            '/^srcset$/i' => Element::ATTR_CS_STRING,
23
            '/^sizes$/i' => Element::ATTR_CS_STRING,
24
            '/^media$/i' => Element::ATTR_CS_STRING
25
        );
26
27
        return array_merge(
28
            $sourceAllowedAttributes,
29
            parent::getAllowedAttributes()
30
        );
31
    }
32
33
    protected function doClean(LoggerInterface $logger)
34
    {
35
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
36
            // Child of "picture" element.
37
            // Child of media element.
38
            $parent = $this->getParent();
39
            if ($parent !== null &&
40
                $parent->getName() != 'picture' &&
41
                !$parent instanceof MediaElement) {
42
                $logger->debug('Element "picture" must be a child of "picture" element or a media element.');
43
44
                return false;
45
            }
46
        }
47
48
        return true;
49
    }
50
}
51