Completed
Push — master ( f59553...fef96a )
by Kevin
02:59
created

Ul::doClean()   C

Complexity

Conditions 8
Paths 7

Size

Total Lines 29
Code Lines 15

Duplication

Lines 29
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 29
loc 29
ccs 0
cts 23
cp 0
rs 5.3846
cc 8
eloc 15
nc 7
nop 1
crap 72
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\Token;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * "ul" element
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-ul-element
14
 */
15
class Ul extends OpenElement
16
{
17 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...
18
    {
19
        // Only "li" and ScriptSupporting elements allowed.
20
        foreach ($this->children as $child) {
21
            if ($child->getType() == Token::COMMENT) {
22
                continue;
23
            }
24
25
            if ($child->getType() != Token::ELEMENT) {
26
                if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
27
                    $logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ul" element.');
28
                    $this->removeChild($child);
29
                }
30
31
                continue;
32
            }
33
34
            if ($child->getName() == 'li' || $child instanceof ScriptSupporting) {
0 ignored issues
show
Bug introduced by
The class Groundskeeper\Tokens\ElementTypes\ScriptSupporting does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
35
                continue;
36
            }
37
38
            if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) {
39
                $logger->debug('Removing ' . $child . '. Only elements "li" and script supporting elements allowed as children of "ul" element.');
40
                $this->removeChild($child);
41
            }
42
        }
43
44
        return true;
45
    }
46
}
47