Completed
Push — 17.x ( 5bcc83...a6d19e )
by Tim
02:03
created

AttributeOptionUpdateObserver::mergeEntity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Observers\AttributeOptionUpdateObserver
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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Observers;
22
23
use TechDivision\Import\Utils\StoreViewCodes;
24
use TechDivision\Import\Attribute\Utils\ColumnKeys;
25
26
/**
27
 * Observer that update's the attribute options found in the additional CSV file.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-attribute
33
 * @link      http://www.techdivision.com
34
 */
35
class AttributeOptionUpdateObserver extends AttributeOptionObserver
36
{
37
38
    /**
39
     * Initialize the EAV attribute option with the passed attributes and returns an instance.
40
     *
41
     * @param array $attr The EAV attribute option attributes
42
     *
43
     * @return array The initialized EAV attribute option
44
     */
45 View Code Duplication
    protected function initializeAttribute(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...
46
    {
47
48
        // load the entity type ID for the value from the system configuration
49
        $entityTypeId = $this->getEntityTypeId();
50
51
        // initialize the data to load the EAV attribute option
52
        $value = $this->getValue(ColumnKeys::VALUE);
53
        $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN);
54
        $attributeCode = $this->getValue(ColumnKeys::ATTRIBUTE_CODE);
55
56
        // try to load the EAV attribute option
57
        if ($attributeOption = $this->loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)) {
58
            return $this->mergeEntity($attributeOption, $attr);
59
        }
60
61
        // simply return the attributes
62
        return $attr;
63
    }
64
65
    /**
66
     * Load's and return's the EAV attribute option with the passed entity type ID, code, store ID and value.
67
     *
68
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load the option for
69
     * @param string  $attributeCode The code of the EAV attribute option to load
70
     * @param integer $storeId       The store ID of the attribute option to load
71
     * @param string  $value         The value of the attribute option to load
72
     *
73
     * @return array The EAV attribute option
74
     */
75
    protected function loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)
76
    {
77
        return $this->getAttributeBunchProcessor()->loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value);
78
    }
79
}
80