AttributeSetUpdateObserver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 37
ccs 0
cts 8
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeAttribute() 0 14 2
A loadAttributeSetByEntityTypeIdAndAttributeSetName() 0 3 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Set\Observers\AttributeSetUpdateObserver
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2019 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-attribute-set
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Attribute\Set\Observers;
16
17
use TechDivision\Import\Attribute\Utils\MemberNames;
18
19
/**
20
 * Observer that add/update's the EAV attribute set itself.
21
 *
22
 * @author    Tim Wagner <[email protected]>
23
 * @copyright 2019 TechDivision GmbH <[email protected]>
24
 * @license   https://opensource.org/licenses/MIT
25
 * @link      https://github.com/techdivision/import-attribute-set
26
 * @link      http://www.techdivision.com
27
 */
28
class AttributeSetUpdateObserver extends AttributeSetObserver
29
{
30
31
    /**
32
     * Initialize the attribute with the passed attributes and returns an instance.
33
     *
34
     * @param array $attr The attribute attributes
35
     *
36
     * @return array The initialized attribute
37
     */
38
    protected function initializeAttribute(array $attr)
39
    {
40
41
        // load the entity type ID and the attribute set name
42
        $entityTypeId = $attr[MemberNames::ENTITY_TYPE_ID];
43
        $attributeSetName = $attr[MemberNames::ATTRIBUTE_SET_NAME];
44
45
        // try to load the EAV attribute set with the entity type code and the attribute set name
46
        if ($entity = $this->loadAttributeSetByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)) {
47
            return $this->mergeEntity($entity, $attr);
48
        }
49
50
        // simply return the attributes
51
        return $attr;
52
    }
53
54
    /**
55
     * Load's and return's the EAV attribute set with the passed entity type ID and attribute set name.
56
     *
57
     * @param string $entityTypeId     The entity type ID of the EAV attribute set to load
58
     * @param string $attributeSetName The attribute set name of the EAV attribute set to return
59
     *
60
     * @return array The EAV attribute set
61
     */
62
    protected function loadAttributeSetByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
63
    {
64
        return $this->getAttributeSetBunchProcessor()->loadAttributeSetByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName);
65
    }
66
}
67