AttributeSetCleanUpObserver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 40
ccs 0
cts 10
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addEntityTypeCodeAndAttributeSetNameIdMapping() 0 3 1
A process() 0 19 4
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Set\Observers\AttributeSetCleanUpObserver
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\ColumnKeys;
18
19
/**
20
 * Clean-Up after importing the EAV attribute set row.
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 AttributeSetCleanUpObserver extends AbstractAttributeSetObserver
29
{
30
31
    /**
32
     * Process the observer's business logic.
33
     *
34
     * @return array The processed row
35
     */
36
    protected function process()
37
    {
38
39
        // load the entity type code and attribute set name
40
        $entityTypeCode = $this->getValue(ColumnKeys::ENTITY_TYPE_CODE);
41
        $attributeSetName = $this->getValue(ColumnKeys::ATTRIBUTE_SET_NAME);
42
43
        // query whether or not we've found a line with a attribute group definition
44
        if ($entityTypeCode === null && $attributeSetName === null) {
45
            return;
46
        }
47
48
        // query whether or not, we've found a new entity type code/attribute set name => means we've found a new attribute set
49
        if ($this->hasBeenProcessed($entityTypeCode, $attributeSetName)) {
50
            return;
51
        }
52
53
        // add the entity type code + attribute set name => entity ID mapping
54
        $this->addEntityTypeCodeAndAttributeSetNameIdMapping($entityTypeCode, $attributeSetName);
55
    }
56
57
    /**
58
     * Map's the passed entity type code and attribute set name to the attribute set ID that has been created recently.
59
     *
60
     * @param string $entityTypeCode   The entity type code to map
61
     * @param string $attributeSetName The attribute set name to map
62
     *
63
     * @return void
64
     */
65
    public function addEntityTypeCodeAndAttributeSetNameIdMapping($entityTypeCode, $attributeSetName)
66
    {
67
        $this->getSubject()->addEntityTypeCodeAndAttributeSetNameIdMapping($entityTypeCode, $attributeSetName);
68
    }
69
}
70