Completed
Push — master ( 9d450b...0b908e )
by Kevin
02:19
created

Link::getAllowedAttrbutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Groundskeeper\Tokens\Elements;
4
5
class Link extends ClosedElement
6
{
7
    protected function getAllowedAttrbutes()
8
    {
9
        $linkAllowedAttributes = array(
10
            '/^href$/i' => Element::ATTR_URI,
11
            '/^crossorigin$/i' => Element::ATTR_CS_STRING,
12
            '/^rel$/i' => Element::ATTR_CS_STRING,
13
            '/^media$/i' => Element::ATTR_CS_STRING,
14
            '/^hreflang$/i' => Element::ATTR_CS_STRING,
15
            '/^type$/i' => Element::ATTR_CS_STRING,
16
            '/^sizes$/i' => Element::ATTR_CS_STRING
17
        );
18
19
        return array_merge(
20
            $linkAllowedAttributes,
21
            parent::getAllowedAttrbutes()
22
        );
23
    }
24
25 View Code Duplication
    public function validate(Configuration $configuration)
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...
26
    {
27
        parent::validate($configuration);
28
29
        // If not valid, then we are done.
30
        if (!$this->isValid) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->isValid of type null|boolean is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
31
            return;
32
        }
33
34
        // If no cleaning, then we are done.
35
        if ($configuration->get('clean-strategy') == 'none') {
36
            return;
37
        }
38
39
        // Must have "href" attribute.
40
        if (!$this->hasAttribute('href')) {
41
            $this->handleValidationError(
42
                $configuration,
43
                'Link element must have "href" attribute.'
44
            );
45
        }
46
47
        // Must have either "rel" or "itemprop" attribute, but not both.
48
        /// @todo
49
    }
50
}
51