Completed
Push — master ( 817727...d8e3ee )
by Kevin
03:58
created

Menu::removeInvalidChildren()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 9.4924

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 18
ccs 10
cts 14
cp 0.7143
rs 7.7777
cc 8
eloc 11
nc 4
nop 1
crap 9.4924
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\NonParticipating;
10
use Groundskeeper\Tokens\Token;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * "menu" element
15
 *
16
 * https://html.spec.whatwg.org/multipage/semantics.html#the-menu-element
17
 */
18
class Menu extends OpenElement implements FlowContent
19
{
20 1
    protected function getAllowedAttributes()
21
    {
22
        $menuAllowedAttributes = array(
23 1
            '/^type$/i' => Element::ATTR_CI_ENUM . '("","context","toolbar"|"context")',
24
            '/^label$/i' => Element::ATTR_CS_STRING
25 1
        );
26
27 1
        return array_merge(
28 1
            $menuAllowedAttributes,
29 1
            parent::getAllowedAttributes()
30 1
        );
31
    }
32
33 1 View Code Duplication
    protected function fixSelf(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...
34
    {
35 1
        if (!$this->hasAttribute('type')) {
36 1
            $logger->debug('Modifying ' . $this . '. Adding the default "type" attribute for the "menu" element.');
37 1
            $this->addAttribute('type', 'context');
38 1
        }
39 1
    }
40
41 1
    protected function removeInvalidChildren(LoggerInterface $logger)
42
    {
43
        // Only "li" and ScriptSupporting elements allowed.
44 1
        foreach ($this->children as $child) {
45 1
            if ($child instanceof NonParticipating) {
46
                continue;
47
            }
48
49 1
            if (!$child instanceof Li &&
50 1
                !$child instanceof Menuitem &&
0 ignored issues
show
Bug introduced by
The class Groundskeeper\Tokens\Elements\Menuitem 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...
51 1
                !$child instanceof Hr &&
52 1
                !$child instanceof Menu &&
53 1
                !$child instanceof ScriptSupporting) {
0 ignored issues
show
Bug introduced by
The class Groundskeeper\Tokens\Elements\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...
54
                $logger->debug('Removing ' . $child . '. Only elements "li", "menuitem", "hr", "menu", and script supporting elements allowed as children of "menu" element.');
55
                $this->removeChild($child);
56
            }
57 1
        }
58 1
    }
59
}
60