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

Author   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 27.27 %

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 12
loc 44
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 12 12 2
A createElement() 0 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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