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

Author   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 10 2
A createElement() 0 8 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\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($element->nodeValue);
31 3
            $node->setAuthor($author);
32 3
        }
33
34 3
        return $this;
35
    }
36
37
    /**
38
     * creates the accurate DomElement content according to the $item's property
39
     *
40
     * @param  \DomDocument  $document
41
     * @param  NodeInterface $node
42
     * @return \DomElement|null
43
     */
44 2
    public function createElement(\DomDocument $document, NodeInterface $node)
45
    {
46 2
        if ($node instanceof ItemInterface && !is_null($node->getAuthor())) {
47 1
            return $document->createElement($this->getNodeName(), $node->getAuthor()->getName());
48
        }
49
50 1
        return;
51
    }
52
}
53