Passed
Pull Request — master (#1)
by Tim
03:10
created

AttributeGroupObserver::getAttributeSetByAttributeSetName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Set\Observers\AttributeGroupObserver
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-attribute-set
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Set\Observers;
22
23
use TechDivision\Import\Attribute\Set\Utils\ColumnKeys;
24
use TechDivision\Import\Attribute\Set\Utils\MemberNames;
25
26
/**
27
 * Observer that create's the EAV attribute group itself.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2019 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-set
33
 * @link      http://www.techdivision.com
34
 */
35
class AttributeGroupObserver extends AbstractAttributeSetObserver
36
{
37
38
    /**
39
     * Process the observer's business logic.
40
     *
41
     * @return void
42
     */
43
    protected function process()
44
    {
45
46
        // prepare the attribue set values
47
        $attributeSetGroup = $this->initializeAttribute($this->prepareAttributes());
48
49
        // persist the entity
50
        $this->persistAttributeGroup($attributeSetGroup);
51
    }
52
53
    /**
54
     * Prepare the attributes of the entity that has to be persisted.
55
     *
56
     * @return array The prepared attributes
57
     */
58
    protected function prepareAttributes()
59
    {
60
61
        // load the last attribute set
62
        $attributeSet = $this->getLastAttributeSet();
63
64
        // load the attribute set values from the column
65
        $defaultId = $this->getValue(ColumnKeys::DEFAULT_ID, 0);
66
        $sortOrder = $this->getValue(ColumnKeys::ATTRIBUTE_GROUP_SORT_ORDER, 0);
67
        $tabGroupCode = $this->getValue(ColumnKeys::ATTRIBUTE_GROUP_TAB_GROUP_CODE);
68
        $attributeGroupName = $this->getValue(ColumnKeys::ATTRIBUTE_GROUP_NAME);
69
        $attributeGroupCode = $this->getValue(ColumnKeys::ATTRIBUTE_GROUP_CODE);
70
71
        // return the prepared product
72
        return $this->initializeEntity(
73
            array(
74
                MemberNames::ATTRIBUTE_SET_ID     => $attributeSet[MemberNames::ATTRIBUTE_SET_ID],
75
                MemberNames::ATTRIBUTE_GROUP_NAME => $attributeGroupName,
76
                MemberNames::SORT_ORDER           => $sortOrder,
77
                MemberNames::DEFAULT_ID           => $defaultId,
78
                MemberNames::ATTRIBUTE_GROUP_CODE => $attributeGroupCode,
79
                MemberNames::TAB_GROUP_CODE       => $tabGroupCode
80
            )
81
        );
82
    }
83
84
    /**
85
     * Initialize the attribute with the passed attributes and returns an instance.
86
     *
87
     * @param array $attr The attribute attributes
88
     *
89
     * @return array The initialized attribute
90
     */
91
    protected function initializeAttribute(array $attr)
92
    {
93
        return $attr;
94
    }
95
96
    /**
97
     * Return's the entity type code to be used.
98
     *
99
     * @return string The entity type code to be used
100
     */
101
    protected function getEntityTypeCode()
102
    {
103
        return $this->getSubject()->getEntityTypeCode();
104
    }
105
106
    /**
107
     * Persist the passed attribute group.
108
     *
109
     * @param array $attributeGroup The attribute group to persist
110
     *
111
     * @return void
112
     */
113
    protected function persistAttributeGroup(array $attributeGroup)
114
    {
115
        return $this->getAttributeSetBunchProcessor()->persistAttributeGroup($attributeGroup);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getAttributeSetBu...eGroup($attributeGroup) targeting TechDivision\Import\Attr...persistAttributeGroup() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
116
    }
117
}
118