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

Dfn   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 44 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 5
c 3
b 1
f 1
lcom 2
cbo 2
dl 11
loc 25
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A removeInvalidChildren() 0 10 3
A removeInvalidSelf() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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