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

LinkUpdateObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
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 41
loc 41
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeProductLink() 16 16 2
A loadProductLink() 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\LinkUpdateObserver
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 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 LinkUpdateObserver extends LinkObserver
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 with the passed attributes and returns an instance.
39
     *
40
     * @param array $attr The product link attributes
41
     *
42
     * @return array The initialized product link
43
     */
44
    protected function initializeProductLink(array $attr)
45
    {
46
47
        // load the product/linked product/link type ID
48
        $productId = $attr[MemberNames::PRODUCT_ID];
49
        $linkTypeId = $attr[MemberNames::LINK_TYPE_ID];
50
        $linkedProductId = $attr[MemberNames::LINKED_PRODUCT_ID];
51
52
        // try to load the link with the passed product/linked product/link type ID
53
        if ($entity = $this->loadProductLink($productId, $linkedProductId, $linkTypeId)) {
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...ers\LinkUpdateObserver>.

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
     * Load's the link with the passed product/linked product/link type ID.
63
     *
64
     * @param integer $productId       The product ID of the link to load
65
     * @param integer $linkedProductId The linked product ID of the link to load
66
     * @param integer $linkTypeId      The link type ID of the product to load
67
     *
68
     * @return array The link
69
     */
70
    protected function loadProductLink($productId, $linkedProductId, $linkTypeId)
71
    {
72
        return $this->getSubject()->loadProductLink($productId, $linkedProductId, $linkTypeId);
73
    }
74
}
75