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

Link::setProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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