Picture   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C removeInvalidChildren() 0 27 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