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

Body   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 29.27 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 4
c 5
b 1
f 3
lcom 0
cbo 2
dl 12
loc 41
ccs 26
cts 26
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getAllowedAttributes() 0 25 1
A removeInvalidSelf() 12 12 3

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\Element;
6
use Groundskeeper\Tokens\ElementTypes\OpenElement;
7
use Groundskeeper\Tokens\ElementTypes\SectioningRoot;
8
use Groundskeeper\Tokens\Token;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * "body" element
13
 *
14
 * https://html.spec.whatwg.org/multipage/semantics.html#the-body-element
15
 */
16
class Body extends OpenElement implements SectioningRoot
17
{
18 1
    protected function getAllowedAttributes()
19
    {
20
        $bodyAllowedAttributes = array(
21 1
            '/^onafterprint$/i' => Element::ATTR_JS,
22 1
            '/^onbeforeprint$/i' => Element::ATTR_JS,
23 1
            '/^onbeforeunload$/i' => Element::ATTR_JS,
24 1
            '/^onhashchange$/i' => Element::ATTR_JS,
25 1
            '/^onlanguagechange$/i' => Element::ATTR_JS,
26 1
            '/^onmessage$/i' => Element::ATTR_JS,
27 1
            '/^onoffline$/i' => Element::ATTR_JS,
28 1
            '/^ononline$/i' => Element::ATTR_JS,
29 1
            '/^onpagehide$/i' => Element::ATTR_JS,
30 1
            '/^onpageshow$/i' => Element::ATTR_JS,
31 1
            '/^onpopstate$/i' => Element::ATTR_JS,
32 1
            '/^onrejectionhandled$/i' => Element::ATTR_JS,
33 1
            '/^onstorage$/i' => Element::ATTR_JS,
34 1
            '/^onunhandledrejection$/i' => Element::ATTR_JS,
35
            '/^onunload$/i' => Element::ATTR_JS
36 1
        );
37
38 1
        return array_merge(
39 1
            $bodyAllowedAttributes,
40 1
            parent::getAllowedAttributes()
41 1
        );
42
    }
43
44 34 View Code Duplication
    protected function removeInvalidSelf(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...
45
    {
46
        // "body" element must be a child of "html" element.
47 34
        if ($this->getParent() !== null &&
48 34
            !($this->getParent() instanceof Html)) {
49 1
            $logger->debug('Removing ' . $this . '. Must be a child of "html" element.');
50
51 1
            return true;
52
        }
53
54 33
        return false;
55
    }
56
}
57