Base   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B removeInvalidSelf() 0 18 5
A getAllowedAttributes() 0 12 1
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
/**
11
 * "base" element
12
 *
13
 * https://html.spec.whatwg.org/multipage/semantics.html#the-base-element
14
 */
15
class Base extends ClosedElement implements MetadataContent
16
{
17 4
    protected function getAllowedAttributes()
18
    {
19
        $baseAllowedAttributes = array(
20 4
            '/^href$/i' => Attribute::URI,
21
            '/^target$/i' => Attribute::CS_STRING
22
        );
23
24 4
        return array_merge(
25 4
            $baseAllowedAttributes,
26 4
            parent::getAllowedAttributes()
27
        );
28
    }
29
30 4
    protected function removeInvalidSelf(LoggerInterface $logger) : bool
31
    {
32
        // "base" element must be child of "head" element.
33 4
        if ($this->getParent() !== null && !($this->getParent() instanceof Head)) {
34 1
            $logger->debug('Removing ' . $this . '. Must be a "head" element child.');
35
36 1
            return true;
37
        }
38
39
        // Must have either "href" or "target" attribute or both.
40 3
        if (!$this->hasAttribute('href') && !$this->hasAttribute('target')) {
41 1
            $logger->debug('Removing ' . $this . '. Must have either the "href" or "target" attribute or both.');
42
43 1
            return true;
44
        }
45
46 2
        return false;
47
    }
48
}
49