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

Author   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createElement() 0 13 3
A setProperty() 0 12 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 2
    public function setProperty(NodeInterface $node, \DOMElement $element)
28
    {
29 2
        if ($node instanceof ItemInterface) {
30 2
          $author = $node->newAuthor();
31 2
          $author->setName($this->getChildValue($element, 'name'));
32 2
          $author->setUri($this->getChildValue($element, 'uri'));
33 2
          $author->setEmail($this->getChildValue($element, 'email'));
34 2
          $node->setAuthor($author);
35 2
        }
36
37 2
        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 2
    public function createElement(\DomDocument $document, NodeInterface $node)
48
    {
49 2
        if ($node instanceof ItemInterface  && !is_null($node->getAuthor())) {
50 1
            $element = $document->createElement(static::NODE_NAME);
51 1
            $element->appendChild($document->createElement('name', $node->getAuthor()->getName()));
52 1
            $element->appendChild($document->createElement('uri', $node->getAuthor()->getUri()));
53 1
            $element->appendChild($document->createElement('email', $node->getAuthor()->getEmail()));
54
55 1
            return $element;
56
        }
57
58 1
        return;
59
    }
60
61
}
62