Completed
Push — master ( 9fbe45...817727 )
by Kevin
03:24
created

Picture::doClean()   C

Complexity

Conditions 9
Paths 2

Size

Total Lines 47
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 47
ccs 0
cts 34
cp 0
rs 5.2941
cc 9
eloc 24
nc 2
nop 1
crap 90
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\EmbeddedContent;
7
use Groundskeeper\Tokens\ElementTypes\FlowContent;
8
use Groundskeeper\Tokens\ElementTypes\OpenElement;
9
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
10
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
11
use Groundskeeper\Tokens\Token;
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * "picture" element
16
 *
17
 * https://html.spec.whatwg.org/multipage/semantics.html#the-picture-element
18
 */
19
class Picture extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent
20
{
21
    protected function removeInvalidChildren(LoggerInterface $logger)
22
    {
23
        $encounteredImgElement = false;
24
        foreach ($this->children as $child) {
25
            if ($child->getType() == Token::COMMENT) {
26
                continue;
27
            }
28
29
            if ($child->getType() !== Token::ELEMENT) {
30
                $logger->debug('Removing ' . $child); /// @todo better message
31
                $this->removeChild($child);
32
33
                continue;
34
            }
35
36
            if ($child instanceof ScriptSupporting) {
37
                continue;
38
            }
39
40
            if ($child->getName() == 'img') {
41
                if ($encounteredImgElement) {
42
                    $logger->debug('Removing ' . $child . '. Only one "img" element allowed as child of "picture" element.');
43
                    $this->removeChild($child);
44
45
                    continue;
46
                }
47
48
                $encounteredImgElement = true;
49
50
                continue;
51
            }
52
53 View Code Duplication
            if ($child->getName() != 'source') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
54
                $logger->debug('Removing ' . $child . '. Only one "img" element and zero to many "source" elements allowed as children of the "picture" element.');
55
                $this->removeChild($child);
56
57
                continue;
58
            }
59
        }
60
    }
61
}
62