Completed
Push — issue/134 ( 534dd9 )
by Alex
02:01
created

Author   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

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