Completed
Push — master ( a9b7ce...a1aea0 )
by Tim
11s
created

VariantSuperAttributeUpdateObserver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 75
ccs 0
cts 26
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeProductSuperAttribute() 0 15 2
A initializeProductSuperAttributeLabel() 0 15 2
A loadProductSuperAttribute() 0 4 1
A loadProductSuperAttributeLabel() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Variant\Observers\VariantSuperAttributeUpdateObserver
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-variant
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Variant\Observers;
22
23
use TechDivision\Import\Product\Variant\Utils\MemberNames;
24
25
/**
26
 * Oberserver that provides functionality for the product variant super attribute labels 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-variant
32
 * @link      http://www.techdivision.com
33
 */
34
class VariantSuperAttributeUpdateObserver extends VariantSuperAttributeObserver
35
{
36
37
    /**
38
     * Initialize the product super attribute with the passed attributes and returns an instance.
39
     *
40
     * @param array $attr The product super attribute attributes
41
     *
42
     * @return array The initialized product super attribute
43
     */
44
    protected function initializeProductSuperAttribute(array $attr)
45
    {
46
47
        // load product/attribute ID
48
        $productId = $attr[MemberNames::PRODUCT_ID];
49
        $attributeId = $attr[MemberNames::ATTRIBUTE_ID];
50
51
        // query whether or not, the product super attribute already exists
52
        if ($entity = $this->loadProductSuperAttribute($productId, $attributeId)) {
53
            return $this->mergeEntity($entity, $attr);
0 ignored issues
show
Bug introduced by
The method mergeEntity() does not seem to exist on object<TechDivision\Impo...ttributeUpdateObserver>.

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...
54
        }
55
56
        // simply return the attributes
57
        return $attr;
58
    }
59
60
    /**
61
     * Initialize the product super attribute label with the passed attributes and returns an instance.
62
     *
63
     * @param array $attr The product super attribute label attributes
64
     *
65
     * @return array The initialized product super attribute label
66
     */
67
    protected function initializeProductSuperAttributeLabel(array $attr)
68
    {
69
70
        // load product super attribute/store ID
71
        $storeId = $attr[MemberNames::STORE_ID];
72
        $productSuperAttributeId = $attr[MemberNames::PRODUCT_SUPER_ATTRIBUTE_ID];
73
74
        // query whether or not, the product super attribute label already exists
75
        if ($entity = $this->loadProductSuperAttributeLabel($productSuperAttributeId, $storeId)) {
76
            return $this->mergeEntity($entity, $attr);
0 ignored issues
show
Bug introduced by
The method mergeEntity() does not seem to exist on object<TechDivision\Impo...ttributeUpdateObserver>.

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...
77
        }
78
79
        // simply return the attributes
80
        return $attr;
81
    }
82
83
    /**
84
     * Load's the product super attribute with the passed product/attribute ID.
85
     *
86
     * @param integer $productId   The entity ID of the product super attribute's product
87
     * @param integer $attributeId The attribute ID of the product super attributes attribute
88
     *
89
     * @return array The product super attribute
90
     */
91
    protected function loadProductSuperAttribute($productId, $attributeId)
92
    {
93
        return $this->getSubject()->loadProductSuperAttribute($productId, $attributeId);
94
    }
95
96
    /**
97
     * Load's the product super attribute label with the passed product super attribute/store ID.
98
     *
99
     * @param integer $productSuperAttributeId The product super attribute ID of the product super attribute label
100
     * @param integer $storeId                 The store ID of the product super attribute label
101
     *
102
     * @return array The product super attribute label
103
     */
104
    protected function loadProductSuperAttributeLabel($productSuperAttributeId, $storeId)
105
    {
106
        return $this->getSubject()->loadProductSuperAttributeLabel($productSuperAttributeId, $storeId);
107
    }
108
}
109