Completed
Push — issue/87 ( bbd942...1f15a7 )
by Alex
06:53
created

Link::createElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
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 4
    public function setProperty(NodeInterface $node, \DOMElement $element)
27
    {
28 4
        if ($element->hasAttribute('href')) {
29 4
            $node->setLink($element->getAttribute('href'));
30 4
        }
31
32 4
        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 3
    public function createElement(\DomDocument $document, NodeInterface $node)
43
    {
44 3
        $element = $document->createElement(static::NODE_NAME);
45 3
        $element->setAttribute('href', $node->getLink());
46
47 3
        return $element;
48
    }
49
}
50