Meta::removeInvalidSelf()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 6
cts 6
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
crap 4
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