Completed
Push — master ( 817727...d8e3ee )
by Kevin
03:58
created

Dfn::removeInvalidChildren()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Tokens\ElementTypes\FlowContent;
6
use Groundskeeper\Tokens\ElementTypes\InlineElement;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
9
use Groundskeeper\Tokens\NonParticipating;
10
use Groundskeeper\Tokens\Token;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * "dfn" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/semantics.html#the-dfn-element
17
 */
18
class Dfn extends OpenElement implements FlowContent, PhrasingContent, InlineElement
19
{
20
    protected function removeInvalidChildren(LoggerInterface $logger)
21
    {
22
        // There must be no dfn element descendants.
23
        foreach ($this->children as $child) {
24
            if ($child instanceof Dfn) {
25
                $logger->debug('Removing ' . $child . '. Element "dfn" cannot contain "dfn" elements.');
26
                $this->removeChild($child);
27
            }
28
        }
29
    }
30
31 View Code Duplication
    protected function removeInvalidSelf(LoggerInterface $logger)
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...
32
    {
33
        $dfn = new self($this->configuration);
0 ignored issues
show
Bug introduced by
The call to Dfn::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
34
        if ($this->hasAncestor($dfn)) {
35
            $logger->debug('Removing ' . $child . '. Element "dfn" cannot contain "dfn" elements.');
0 ignored issues
show
Bug introduced by
The variable $child does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
37
            return true;
38
        }
39
40
        return false;
41
    }
42
}
43