Completed
Pull Request — master (#37)
by Tim
03:54
created

AttributeSetObserver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 60
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 1
A process() 0 6 1
A setAttributeSet() 0 4 1
A getAttributeSetByAttributeSetName() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Observers\AttributeSetObserver
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Observers;
22
23
use TechDivision\Import\Utils\ColumnKeys;
24
25
/**
26
 * Observer that prepares the attribute set found in the CSV file
27
 * in the row 'attribute_set_code'.
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
33
 * @link      http://www.techdivision.com
34
 */
35
class AttributeSetObserver extends AbstractObserver
36
{
37
38
    /**
39
     * Will be invoked by the action on the events the listener has been registered for.
40
     *
41
     * @param array $row The row to handle
42
     *
43
     * @return array The modified row
44
     * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle()
45
     */
46
    public function handle(array $row)
47
    {
48
49
        // initialize the row
50
        $this->setRow($row);
51
52
        // process the functionality and return the row
53
        $this->process();
54
55
        // return the processed row
56
        return $this->getRow();
57
    }
58
59
    /**
60
     * Process the observer's business logic.
61
     *
62
     * @return array The processed row
63
     */
64
    protected function process()
65
    {
66
67
        // load and set the attribute set
68
        $this->setAttributeSet($this->getAttributeSetByAttributeSetName($this->getValue(ColumnKeys::ATTRIBUTE_SET_CODE)));
69
    }
70
71
    /**
72
     * Set's the attribute set of the product that has to be created.
73
     *
74
     * @param array $attributeSet The attribute set
75
     *
76
     * @return void
77
     */
78
    protected function setAttributeSet(array $attributeSet)
79
    {
80
        $this->getSubject()->setAttributeSet($attributeSet);
81
    }
82
83
    /**
84
     * Return's the attribute set with the passed attribute set name.
85
     *
86
     * @param string $attributeSetName The name of the requested attribute set
87
     *
88
     * @return array The attribute set data
89
     */
90
    protected function getAttributeSetByAttributeSetName($attributeSetName)
91
    {
92
        return $this->getSubject()->getAttributeSetByAttributeSetName($attributeSetName);
93
    }
94
}
95