Completed
Push — master ( e0ac7a...8eddfc )
by Kevin
03:21
created

Ol   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 61.36 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 8
c 3
b 0
f 3
lcom 1
cbo 3
dl 27
loc 44
ccs 25
cts 25
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 13 1
C doClean() 27 27 7

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\Configuration;
6
use Groundskeeper\Tokens\Element;
7
use Groundskeeper\Tokens\ElementTypes\FlowContent;
8
use Groundskeeper\Tokens\ElementTypes\OpenElement;
9
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting;
10
use Groundskeeper\Tokens\Token;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * "ol" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/semantics.html#the-ol-element
17
 */
18
class Ol extends OpenElement implements FlowContent
19
{
20 1
    protected function getAllowedAttributes()
21
    {
22
        $olAllowedAttributes = array(
23 1
            '/^reversed$/i' => Element::ATTR_BOOL,
24 1
            '/^start$/i' => Element::ATTR_INT,
25 1
            '/^type$/i' => Element::ATTR_CS_STRING,
26 1
        );
27
28 1
        return array_merge(
29 1
            $olAllowedAttributes,
30 1
            parent::getAllowedAttributes()
31 1
        );
32
    }
33
34 1 View Code Duplication
    protected function doClean(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...
35
    {
36 1
        if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
37
            // Only "li" and ScriptSupporting elements allowed.
38 1
            foreach ($this->children as $child) {
39 1
                if ($child->getType() == Token::COMMENT) {
40 1
                    continue;
41
                }
42
43 1
                if ($child->getType() != Token::ELEMENT) {
44 1
                    $logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ol" element.');
45 1
                    $this->removeChild($child);
46
47 1
                    continue;
48
                }
49
50 1
                if ($child->getName() == 'li' || $child instanceof ScriptSupporting) {
51 1
                    continue;
52
                }
53
54 1
                $logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ol" element.');
55 1
                $this->removeChild($child);
56 1
            }
57 1
        }
58
59 1
        return true;
60
    }
61
}
62