Completed
Push — issue/134 ( d0dc5e...07c20b )
by Alex
01:47
created

Author::setProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 8
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\ItemInterface;
14
use FeedIo\Feed\NodeInterface;
15
use FeedIo\RuleAbstract;
16
17
class Author extends RuleAbstract
18
{
19
    const NODE_NAME = 'author';
20
21
    /**
22
     * @param  NodeInterface $node
23
     * @param  \DOMElement   $element
24
     * @return mixed
25
     */
26 3
    public function setProperty(NodeInterface $node, \DOMElement $element)
27
    {
28 3
        if ($node instanceof ItemInterface) {
29 3
            $author = $node->newAuthor();
30 3
            $author->setName($this->getChildValue($element, 'name'));
31 3
            $author->setUri($this->getChildValue($element, 'uri'));
32 3
            $author->setEmail($this->getChildValue($element, 'email'));
33 3
            $node->setAuthor($author);
34 3
        }
35
36 3
        return $this;
37
    }
38
39
    /**
40
     * creates the accurate DomElement content according to the $item's property
41
     *
42
     * @param  \DomDocument  $document
43
     * @param  NodeInterface $node
44
     * @return \DomElement
45
     */
46 2
    public function createElement(\DomDocument $document, NodeInterface $node)
47
    {
48 2
        if ($node instanceof ItemInterface  && !is_null($node->getAuthor())) {
49 1
            $element = $document->createElement(static::NODE_NAME);
50 1
            $element->appendChild($document->createElement('name', $node->getAuthor()->getName()));
51 1
            $element->appendChild($document->createElement('uri', $node->getAuthor()->getUri()));
52 1
            $element->appendChild($document->createElement('email', $node->getAuthor()->getEmail()));
53
54 1
            return $element;
55
        }
56
57 1
        return;
58
    }
59
}
60