Completed
Push — issue/87 ( bbd942 )
by Alex
04:44
created

Link::setProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
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\RuleAbstract;
15
16
class Link extends RuleAbstract
17
{
18
19
    const NODE_NAME = 'link';
20
21
    /**
22
     * @param  NodeInterface $node
23
     * @param  \DOMElement   $element
24
     * @return mixed
25
     */
26 2
    public function setProperty(NodeInterface $node, \DOMElement $element)
27
    {
28 2
        if ($element->hasAttribute('href')) {
29 2
            $node->setLink($element->getAttribute('href'));
30 2
        }
31
32 2
        return $this;
33
    }
34
35
    /**
36
     * creates the accurate DomElement content according to the $item's property
37
     *
38
     * @param  \DomDocument  $document
39
     * @param  NodeInterface $node
40
     * @return \DomElement
41
     */
42
    public function createElement(\DomDocument $document, NodeInterface $node)
43
    {
44
        $element = $document->createElement(static::NODE_NAME);
45
        $element->setAttribute('href', $node->getLink());
46
47
        return $element;
48
    }
49
}
50