Completed
Push — master ( 9fbe45...817727 )
by Kevin
03:24
created

Time::removeInvalidChildren()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
ccs 0
cts 15
cp 0
rs 8.8571
cc 5
eloc 9
nc 5
nop 1
crap 30
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
use Groundskeeper\Configuration;
6
use Groundskeeper\Tokens\ElementTypes\FlowContent;
7
use Groundskeeper\Tokens\ElementTypes\OpenElement;
8
use Groundskeeper\Tokens\ElementTypes\PhrasingContent;
9
use Groundskeeper\Tokens\Token;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * "time" element
14
 *
15
 * https://html.spec.whatwg.org/multipage/semantics.html#the-time-element
16
 */
17
class Time extends OpenElement implements FlowContent, PhrasingContent
18
{
19
    protected function getAllowedAttributes()
20
    {
21
        $timeAllowedAttributes = array(
22
            '/^datetime$/i' => Element::ATTR_CS_STRING
23
        );
24
25
        return array_merge(
26
            $timeAllowedAttributes,
27
            parent::getAllowedAttributes()
28
        );
29
    }
30
31 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...
32
    {
33
        // If attribute "datetime" is not present, then only TEXT type
34
        // children allowed.
35
        if (!$this->hasAttribute('datetime')) {
36
            foreach ($this->children as $child) {
37
                if ($child->getType() == Token::COMMENT) {
38
                    continue;
39
                }
40
41
                if ($child->getType() != Token::TEXT) {
42
                    $logger->debug('Removing ' . $child . '. Element "time" without "datetime" attribute may only contain TEXT.');
43
                    $this->removeChild($child);
44
45
                    continue;
46
                }
47
            }
48
        }
49
    }
50
}
51