Completed
Push — issue/87 ( bbd942 )
by Alex
04:44
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
20
    const NODE_NAME = 'author';
21
22
    /**
23
     * @param  NodeInterface $node
24
     * @param  \DOMElement   $element
25
     * @return mixed
26
     */
27 1
    public function setProperty(NodeInterface $node, \DOMElement $element)
28
    {
29 1
        if ($node instanceof ItemInterface) {
30 1
          $author = $node->newAuthor();
31 1
          $author->setName($this->getChildValue($element, 'name'));
32 1
          $author->setUri($this->getChildValue($element, 'uri'));
33 1
          $author->setEmail($this->getChildValue($element, 'email'));
34 1
          $node->setAuthor($author);
35 1
        }
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * creates the accurate DomElement content according to the $item's property
42
     *
43
     * @param  \DomDocument  $document
44
     * @param  NodeInterface $node
45
     * @return \DomElement
46
     */
47
    public function createElement(\DomDocument $document, NodeInterface $node)
48
    {
49
        if ($node instanceof ItemInterface  && !is_null($node->getAuthor())) {
50
            $element = $document->createElement(static::NODE_NAME);
51
            $element->appendChild($document->createElement('name', $node->getAuthor()->getName()));
52
            $element->appendChild($document->createElement('uri', $node->getAuthor()->getUri()));
53
            $element->appendChild($document->createElement('email', $node->getAuthor()->getEmail()));
54
55
            return $element;
56
        }
57
58
        return;
59
    }
60
61
}
62