Completed
Push — issue/134 ( d0dc5e...07c20b )
by Alex
01:47
created

Category   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 10
loc 54
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 10 1
A createCategoryElement() 10 10 2
A createElement() 0 10 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;
12
13
use FeedIo\Feed\Node\CategoryInterface;
14
use FeedIo\Feed\NodeInterface;
15
use FeedIo\RuleAbstract;
16
17
class Category extends RuleAbstract
18
{
19
    const NODE_NAME = 'category';
20
        
21
    /**
22
     * @param  NodeInterface $node
23
     * @param  \DOMElement   $element
24
     * @return mixed
25
     */
26 2
    public function setProperty(NodeInterface $node, \DOMElement $element)
27
    {
28 2
        $category = $node->newCategory();
29 2
        $category->setScheme($this->getAttributeValue($element, 'domain'))
30 2
        ->setLabel($element->nodeValue)
31 2
        ->setTerm($element->nodeValue);
32 2
        $node->addCategory($category);
33
34 2
        return $this;
35
    }
36
37
    /**
38
     * creates the accurate DomElement content according to the $item's property
39
     *
40
     * @param  \DomDocument  $document
41
     * @param  NodeInterface $node
42
     * @return \DomElement|null
43
     */
44 4
    public function createElement(\DomDocument $document, NodeInterface $node)
45
    {
46 4
        if (! is_null($node->getCategories())) {
47 4
            foreach ($node->getCategories() as $category) {
48 4
                yield $this->createCategoryElement($document, $category);
49 4
            }
50 4
        }
51
        
52 4
        return;
53
    }
54
    
55
    /**
56
     * @param  \DomDocument   $document
57
     * @param  CategoryInterface $category
58
     * @return \DomElement
59
     */
60 4 View Code Duplication
    public function createCategoryElement(\DomDocument $document, CategoryInterface $category)
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...
61
    {
62 4
        $element = $document->createElement(
63 4
            $this->getNodeName(),
64 4
            is_null($category->getTerm()) ? $category->getLabel():$category->getTerm()
65 4
            );
66 4
        $element->setAttribute('domain', $category->getScheme());
67
68 4
        return $element;
69
    }
70
}
71