Picture::removeInvalidChildren()   C
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 17
cts 17
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 5
nop 1
crap 7
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\ElementTypes\EmbeddedContent;
6
use Groundskeeper\Tokens\ElementTypes\FlowContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
9
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
10
use Groundskeeper\Tokens\NonParticipating;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * "picture" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/semantics.html#the-picture-element
17
 */
18
class Picture extends OpenElement implements FlowContent, PhrasingContent, EmbeddedContent
19
{
20 2
    protected function removeInvalidChildren(LoggerInterface $logger)
21
    {
22 2
        $encounteredImgElement = false;
23 2
        foreach ($this->children as $child) {
24 2
            if ($child instanceof NonParticipating ||
25 2
                $child instanceof Source ||
26 2
                $child instanceof ScriptSupporting) {
27 1
                continue;
28
            }
29
30 2
            if ($child instanceof Img) {
31 2
                if ($encounteredImgElement) {
32 1
                    $logger->debug('Removing ' . $child . '. Only one "img" element allowed as child of "picture" element.');
33 1
                    $this->removeChild($child);
34
35 1
                    continue;
36
                }
37
38 2
                $encounteredImgElement = true;
39
40 2
                continue;
41
            }
42
43 1
            $logger->debug('Removing ' . $child . '. Only one "img" element and zero to many "source" elements allowed as children of the "picture" element.');
44 1
            $this->removeChild($child);
45
        }
46 2
    }
47
}
48