Tr   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 35
Duplicated Lines 42.86 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 2
dl 15
loc 35
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B removeInvalidSelf() 0 16 6
B removeInvalidChildren() 15 15 6

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\OpenElement;
6
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
7
use Groundskeeper\Tokens\NonParticipating;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * "tr" element
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-tr-element
14
 */
15
class Tr extends OpenElement
16
{
17 4 View Code Duplication
    protected function removeInvalidChildren(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...
18
    {
19
        // Children can be "td", "th", and script supporting elements.
20 4
        foreach ($this->children as $child) {
21 4
            if ($child instanceof NonParticipating ||
22 3
                $child instanceof Td ||
23 3
                $child instanceof Th ||
24 4
                $child instanceof ScriptSupporting) {
25 4
                continue;
26
            }
27
28 1
            $logger->debug('Removing ' . $child . '. Only "td", "th", and script supporting elements allowed as children of "tr" element.');
29 1
            $this->removeChild($child);
30
        }
31 4
    }
32
33 4
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
34
    {
35
        // "table" must be parent.
36 4
        $parent = $this->getParent();
37 4
        if ($parent !== null &&
38 4
            !$parent instanceof Thead &&
39 4
            !$parent instanceof Tbody &&
40 4
            !$parent instanceof Tfoot &&
41 4
            !$parent instanceof Table) {
42 1
            $logger->debug('Removing ' . $this . '. Must be a child of the "thead", "tbody", "tfoot", or "table" elements.');
43
44 1
            return true;
45
        }
46
47 4
        return false;
48
    }
49
}
50