Completed
Push — issue/87 ( bbd942...1f15a7 )
by Alex
06:53
created

Author   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
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 38
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
20
    const NODE_NAME = 'author';
21
22
    /**
23
     * @param  NodeInterface $node
24
     * @param  \DOMElement   $element
25
     * @return mixed
26
     */
27 3
    public function setProperty(NodeInterface $node, \DOMElement $element)
28
    {
29 3
        if ($node instanceof ItemInterface) {
30 3
          $author = $node->newAuthor();
31 3
          $author->setName($element->nodeValue);
32 3
          $node->setAuthor($author);
33 3
        }
34
35 3
        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 2
    public function createElement(\DomDocument $document, NodeInterface $node)
46
    {
47 2
        if ($node instanceof ItemInterface && !is_null($node->getAuthor())) {
48 1
            return $document->createElement($this->getNodeName(), $node->getAuthor()->getName());
49
        }
50
51 1
        return;
52
    }
53
54
}
55