Completed
Push — master ( a993d8...24cef3 )
by Tim
10s
created

LinkAttributePositionUpdateObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 40
loc 40
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeProductLinkAttributeInt() 16 16 2
A loadProductLinkAttributeInt() 4 4 1

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
/**
4
 * TechDivision\Import\Product\Link\Observers\LinkAttributePositionUpdateObserver
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-link
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Link\Observers;
22
23
use TechDivision\Import\Product\Link\Utils\MemberNames;
24
25
/**
26
 * Oberserver that provides functionality for the product link attribute position add/update operation.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product-link
32
 * @link      http://www.techdivision.com
33
 */
34 View Code Duplication
class LinkAttributePositionUpdateObserver extends LinkAttributePositionObserver
0 ignored issues
show
Duplication introduced by
This class 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...
35
{
36
37
    /**
38
     * Initialize the product link attribute with the passed attributes and returns an instance.
39
     *
40
     * @param array $attr The product link attribute
41
     *
42
     * @return array The initialized product link attribute
43
     */
44
    protected function initializeProductLinkAttributeInt(array $attr)
45
    {
46
47
        // load value/link/product link attribute ID
48
        $value = $attr[MemberNames::VALUE];
0 ignored issues
show
Unused Code introduced by
$value is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
        $linkId = $attr[MemberNames::LINK_ID];
50
        $productLinkAttributeId = $attr[MemberNames::PRODUCT_LINK_ATTRIBUTE_ID];
51
52
        // try to load the product link attribute integer value with the passed product link attribute/link ID
53
        if ($entity = $this->loadProductLinkAttributeInt($productLinkAttributeId, $linkId)) {
54
            return $this->mergeEntity($entity, $attr);
0 ignored issues
show
Bug introduced by
The method mergeEntity() does not seem to exist on object<TechDivision\Impo...PositionUpdateObserver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        }
56
57
        // simply return the attributes
58
        return $attr;
59
    }
60
61
    /**
62
     * Return's the product link attribute integer value with the passed product link attribute/link ID.
63
     *
64
     * @param integer $productLinkAttributeId The product link attribute ID of the attributes
65
     * @param integer $linkId                 The link ID of the attribute
66
     *
67
     * @return array The product link attribute integer value
68
     */
69
    protected function loadProductLinkAttributeInt($productLinkAttributeId, $linkId)
70
    {
71
        return $this->getSubject()->loadProductLinkAttributeInt($productLinkAttributeId, $linkId);
72
    }
73
}
74