Completed
Push — 10.x ( 0c1414 )
by Tim
08:49
created

initializeProductLinkAttributeDecimal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 15
loc 15
ccs 0
cts 9
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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 2019 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 2019 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
class LinkAttributePositionUpdateObserver extends LinkAttributePositionObserver
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 View Code Duplication
    protected function initializeProductLinkAttributeInt(array $attr)
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...
45
    {
46
47
        // load link/product link attribute ID
48
        $linkId = $attr[MemberNames::LINK_ID];
49
        $productLinkAttributeId = $attr[MemberNames::PRODUCT_LINK_ATTRIBUTE_ID];
50
51
        // try to load the product link attribute integer value with the passed product link attribute/link ID
52
        if ($entity = $this->loadProductLinkAttributeInt($productLinkAttributeId, $linkId)) {
53
            return $this->mergeEntity($entity, $attr);
54
        }
55
56
        // simply return the attributes
57
        return $attr;
58
    }
59
60
    /**
61
     * Initialize the product link attribute with the passed attributes and returns an instance.
62
     *
63
     * @param array $attr The product link attribute
64
     *
65
     * @return array The initialized product link attribute
66
     */
67 View Code Duplication
    protected function initializeProductLinkAttributeDecimal(array $attr)
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...
68
    {
69
70
        // load link/product link attribute ID
71
        $linkId = $attr[MemberNames::LINK_ID];
72
        $productLinkAttributeId = $attr[MemberNames::PRODUCT_LINK_ATTRIBUTE_ID];
73
74
        // try to load the product link attribute decimal value with the passed product link attribute/link ID
75
        if ($entity = $this->loadProductLinkAttributeDecimal($productLinkAttributeId, $linkId)) {
76
            return $this->mergeEntity($entity, $attr);
77
        }
78
79
        // simply return the attributes
80
        return $attr;
81
    }
82
83
    /**
84
     * Initialize the product link attribute with the passed attributes and returns an instance.
85
     *
86
     * @param array $attr The product link attribute
87
     *
88
     * @return array The initialized product link attribute
89
     */
90 View Code Duplication
    protected function initializeProductLinkAttributeVarchar(array $attr)
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...
91
    {
92
93
        // load link/product link attribute ID
94
        $linkId = $attr[MemberNames::LINK_ID];
95
        $productLinkAttributeId = $attr[MemberNames::PRODUCT_LINK_ATTRIBUTE_ID];
96
97
        // try to load the product link attribute varchar value with the passed product link attribute/link ID
98
        if ($entity = $this->loadProductLinkAttributeVarchar($productLinkAttributeId, $linkId)) {
99
            return $this->mergeEntity($entity, $attr);
100
        }
101
102
        // simply return the attributes
103
        return $attr;
104
    }
105
106
    /**
107
     * Return's the product link attribute integer value with the passed product link attribute/link ID.
108
     *
109
     * @param integer $productLinkAttributeId The product link attribute ID of the attributes
110
     * @param integer $linkId                 The link ID of the attribute
111
     *
112
     * @return array The product link attribute integer value
113
     */
114
    protected function loadProductLinkAttributeInt($productLinkAttributeId, $linkId)
115
    {
116
        return $this->getProductLinkProcessor()->loadProductLinkAttributeInt($productLinkAttributeId, $linkId);
117
    }
118
119
    /**
120
     * Return's the product link attribute decimal value with the passed product link attribute/link ID.
121
     *
122
     * @param integer $productLinkAttributeId The product link attribute ID of the attributes
123
     * @param integer $linkId                 The link ID of the attribute
124
     *
125
     * @return array The product link attribute decimal value
126
     */
127
    protected function loadProductLinkAttributeDecimal($productLinkAttributeId, $linkId)
128
    {
129
        return $this->getProductLinkProcessor()->loadProductLinkAttributeDecimal($productLinkAttributeId, $linkId);
130
    }
131
132
    /**
133
     * Return's the product link attribute varchar value with the passed product link attribute/link ID.
134
     *
135
     * @param integer $productLinkAttributeId The product link attribute ID of the attributes
136
     * @param integer $linkId                 The link ID of the attribute
137
     *
138
     * @return array The product link attribute varchar value
139
     */
140
    protected function loadProductLinkAttributeVarchar($productLinkAttributeId, $linkId)
141
    {
142
        return $this->getProductLinkProcessor()->loadProductLinkAttributeVarchar($productLinkAttributeId, $linkId);
143
    }
144
}
145