Completed
Push — master ( 4c5e3b...48ee6b )
by Alex
09:17
created

Link   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 36
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 6 2
A selectAlternateLink() 0 9 4
A addElement() 0 7 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the feed-io package.
4
 *
5
 * (c) Alexandre Debril <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace FeedIo\Rule\Atom;
12
13
use FeedIo\Feed\NodeInterface;
14
use FeedIo\Rule\Link as BaseLink;
15
16
class Link extends BaseLink
17
{
18
    const NODE_NAME = 'link';
19
20
    /**
21
     * @param  NodeInterface $node
22
     * @param  \DOMElement   $element
23
     */
24 6
    public function setProperty(NodeInterface $node, \DOMElement $element) : void
25
    {
26 6
        if ($element->hasAttribute('href')) {
27 6
            $this->selectAlternateLink($node, $element);
28
        }
29 6
    }
30
31
    protected function selectAlternateLink(NodeInterface $node, \DOMElement $element): void
32
    {
33
        if (
34 5
        ($element->hasAttribute('rel') && $element->getAttribute('rel') == 'alternate')
35
        || is_null($node->getLink())
36 5
        ) {
37 5
            $node->setLink($element->getAttribute('href'));
38
        }
39 5
    }
40 5
41
    /**
42
     * @inheritDoc
43
     */
44
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
45
    {
46
        $element = $document->createElement(static::NODE_NAME);
47
        $element->setAttribute('href', $node->getLink());
48
49
        $rootElement->appendChild($element);
50
    }
51
}
52