Meta   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 51.22 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 21
loc 41
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedAttributes() 0 15 1
A fixSelf() 8 8 3
A removeInvalidSelf() 13 13 4

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\Attribute;
6
use Groundskeeper\Tokens\ElementTypes\ClosedElement;
7
use Groundskeeper\Tokens\ElementTypes\MetadataContent;
8
use Psr\Log\LoggerInterface;
9
10
class Meta extends ClosedElement implements MetadataContent
11
{
12 7
    protected function getAllowedAttributes()
13
    {
14
        $metaAllowedAttributes = array(
15 7
            '/^name$/i' => Attribute::CS_STRING,
16
            '/^http-equiv$/i' => Attribute::CI_ENUM . '("content-language","content-type","default-style","refresh","set-cookie","x-ua-compatible","content-security-policy")',
17
            '/^content$/i' => Attribute::CS_STRING,
18
            '/^charset$/i' => Attribute::CI_STRING,
19
            '/^property$/i' => Attribute::CS_STRING  // Facebook OG attribute name.
20
        );
21
22 7
        return array_merge(
23 7
            $metaAllowedAttributes,
24 7
            parent::getAllowedAttributes()
25
        );
26
    }
27
28 3 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...
29
    {
30
        // "name" attribute requires "content" attribute.
31 3
        if ($this->hasAttribute('name') && !$this->hasAttribute('content')) {
32 1
            $logger->debug('Modifying ' . $this . '. A "meta" element with a "name" attribute requires a "content" attribute.  Adding empty "content" attribute.');
33 1
            $this->addAttribute('content', '');
34
        }
35 3
    }
36
37 3 View Code Duplication
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
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...
38
    {
39
        // If "charset" attribute is present, the must be child of "head" element.
40 3
        if ($this->hasAttribute('charset') && $this->getParent() !== null) {
41 1
            if (!$this->getParent() instanceof Head) {
42 1
                $logger->debug('Removing ' . $this . '. Element "meta" with a "charset" attribute must be a "head" element child.');
43
44 1
                return true;
45
            }
46
        }
47
48 3
        return false;
49
    }
50
}
51