Completed
Push — issue/72 ( 085764 )
by Alex
18:17
created

Author::setProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 12
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
crap 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\Item\AuthorInterface;
14
use FeedIo\Feed\ItemInterface;
15
use FeedIo\Feed\NodeInterface;
16
use FeedIo\RuleAbstract;
17
18
class Author extends RuleAbstract
19
{
20
21
    const NODE_NAME = 'author';
22
23
    /**
24
     * @param  NodeInterface $node
25
     * @param  \DOMElement   $element
26
     * @return mixed
27
     */
28 2 View Code Duplication
    public function setProperty(NodeInterface $node, \DOMElement $element)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30 2
        if ($node instanceof ItemInterface) {
31 2
          $author = $node->newAuthor();
32 2
          $author->setName($this->getAttributeValue($element, 'name'));
33 2
          $author->setUri($this->getAttributeValue($element, 'uri'));
34 2
          $author->setEmail($this->getAttributeValue($element, 'email'));
35 2
          $node->setAuthor($author);
36 2
        }
37
38 2
        return $this;
39
    }
40
41
    /**
42
     * creates the accurate DomElement content according to the $item's property
43
     *
44
     * @param  \DomDocument  $document
45
     * @param  NodeInterface $node
46
     * @return \DomElement
47
     */
48 2
    public function createElement(\DomDocument $document, NodeInterface $node)
49
    {
50 2
        if ($node instanceof ItemInterface  && !is_null($node->getAuthor())) {
51 1
            $element = $document->createElement(static::NODE_NAME);
52 1
            $element->setAttribute('name', $node->getAuthor()->getName());
53 1
            $element->setAttribute('uri', $node->getAuthor()->getUri());
54 1
            $element->setAttribute('email', $node->getAuthor()->getEmail());
55
56 1
            return $element;
57
        }
58
59 1
        return;
60
    }
61
}
62