Completed
Push — issue/72 ( 085764 )
by Alex
18:17
created

Author::createElement()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
crap 3
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;
12
13
use FeedIo\Feed\Item\AuthorInterface;
14
use FeedIo\Feed\ItemInterface;
15
use FeedIo\Feed\NodeInterface;
16
use FeedIo\RuleAbstract;
17
18
class Author extends RuleAbstract
19
{
20
21
    const NODE_NAME = 'author';
22
23
    /**
24
     * @param  NodeInterface $node
25
     * @param  \DOMElement   $element
26
     * @return mixed
27
     */
28 3
    public function setProperty(NodeInterface $node, \DOMElement $element)
29
    {
30 3
        if ($node instanceof ItemInterface) {
31 3
          $author = $node->newAuthor();
32 3
          $author->setName($element->nodeValue);
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|null
45
     */
46 2
    public function createElement(\DomDocument $document, NodeInterface $node)
47
    {
48 2
        if ($node instanceof ItemInterface && !is_null($node->getAuthor())) {
49 1
            return $document->createElement($this->getNodeName(), $node->getAuthor()->getName());
50
        }
51
52 1
        return;
53
    }
54
55
}
56