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

Author::createElement()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
crap 12
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\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 2
    public function setProperty(NodeInterface $node, \DOMElement $element)
28
    {
29 2
        if ($node instanceof ItemInterface) {
30 2
          $author = $node->newAuthor();
31 2
          $author->setName($element->nodeValue);
32 2
          $node->setAuthor($author);
33 2
        }
34
35 2
        return $this;
36
    }
37
38
    /**
39
     * creates the accurate DomElement content according to the $item's property
40
     *
41
     * @param  \DomDocument  $document
42
     * @param  NodeInterface $node
43
     * @return \DomElement|null
44
     */
45
    public function createElement(\DomDocument $document, NodeInterface $node)
46
    {
47
        if ($node instanceof ItemInterface && !is_null($node->getAuthor())) {
48
            return $document->createElement($this->getNodeName(), $node->getAuthor()->getName());
49
        }
50
51
        return;
52
    }
53
54
}
55