Time   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 55.88 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 19
loc 34
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 11 1
B removeInvalidChildren() 19 19 5

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\Attribute;
6
use Groundskeeper\Tokens\ElementTypes\FlowContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
9
use Groundskeeper\Tokens\NonParticipating;
10
use Groundskeeper\Tokens\Text;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * "time" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/semantics.html#the-time-element
17
 */
18
class Time extends OpenElement implements FlowContent, PhrasingContent
19
{
20 1
    protected function getAllowedAttributes()
21
    {
22
        $timeAllowedAttributes = array(
23 1
            '/^datetime$/i' => Attribute::CS_STRING
24
        );
25
26 1
        return array_merge(
27 1
            $timeAllowedAttributes,
28 1
            parent::getAllowedAttributes()
29
        );
30
    }
31
32 2 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...
33
    {
34
        // If attribute "datetime" is not present, then only TEXT type
35
        // children allowed.
36 2
        if (!$this->hasAttribute('datetime')) {
37 2
            foreach ($this->children as $child) {
38 2
                if ($child instanceof NonParticipating) {
39 1
                    continue;
40
                }
41
42 2
                if (!$child instanceof Text) {
43 1
                    $logger->debug('Removing ' . $child . '. Element "time" without "datetime" attribute may only contain TEXT.');
44 1
                    $this->removeChild($child);
45
46 2
                    continue;
47
                }
48
            }
49
        }
50 2
    }
51
}
52