Completed
Pull Request — master (#257)
by
unknown
01:57
created

Author   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 31.43 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 11
loc 35
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 10 2
A addElement() 11 11 2

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 declare(strict_types=1);
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\Rule\Author as BaseAuthor;
16
17
class Author extends BaseAuthor
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) : void
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
37
    /**
38
     * @inheritDoc
39
     */
40 View Code Duplication
    protected function addElement(\DomDocument $document, \DOMElement $rootElement, NodeInterface $node) : void
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...
41
    {
42
        if ($node instanceof ItemInterface) {
43
            $element = $document->createElement(static::NODE_NAME);
44
            $this->appendNonEmptyChild($document, $element, 'name', $node->getAuthor()->getName());
45
            $this->appendNonEmptyChild($document, $element, 'uri', $node->getAuthor()->getUri());
46
            $this->appendNonEmptyChild($document, $element, 'email', $node->getAuthor()->getEmail());
47
48
            $rootElement->appendChild($element);
49
        }
50
    }
51
}
52