Passed
Push — master ( 564b7e...61dc89 )
by Tim
06:19 queued 11s
created

getMsiBunchProcessor()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Msi\Observers\ClearInventorySourceItemObserver
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-product-msi
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Msi\Observers;
22
23
use TechDivision\Import\Product\Msi\Utils\ColumnKeys;
24
use TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface;
25
use TechDivision\Import\Product\Msi\Utils\MemberNames;
26
use TechDivision\Import\Product\Msi\Utils\SqlStatementKeys;
27
28
/**
29
 * Observer that removes the MSI product sourch item with the SKU/Source Code found in the CSV file.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2019 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import-product-msi
35
 * @link      http://www.techdivision.com
36
 */
37
class ClearInventorySourceItemObserver extends AbstractMsiImportObserver
38
{
39
40
    /**
41
     * The MSI bunch processor instance.
42
     *
43
     * @var \TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface
44
     */
45
    protected $msiBunchProcessor;
46
47
    /**
48
     * Initialize the observer with the passed MSI bunch processor instance.
49
     *
50
     * @param \TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface $msiBunchProcessor The MSI bunch processor instance
51
     */
52
    public function __construct(MsiBunchProcessorInterface $msiBunchProcessor)
53
    {
54
        $this->msiBunchProcessor = $msiBunchProcessor;
55
    }
56
57
    /**
58
     * Return's the MSI bunch processor instance.
59
     *
60
     * @return \TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface The MSI bunch processor instance
61
     */
62
    protected function getMsiBunchProcessor()
63
    {
64
        return $this->msiBunchProcessor;
65
    }
66
67
    /**
68
     * Process the observer's business logic.
69
     *
70
     * @return array The processed row
71
     */
72
    protected function process()
73
    {
74
        $this->deleteInventorySourceItem(
75
            array(
76
                MemberNames::SKU         => $this->getValue(ColumnKeys::SKU),
77
                MemberNames::SOURCE_CODE => $this->getValue(ColumnKeys::SOURCE_CODE)
78
            ),
79
            SqlStatementKeys::DELETE_INVENTORY_SOURCE_ITEM_BY_SKU_AND_SOURCE_CODE
80
        );
81
    }
82
83
    /**
84
     * Delete's the entity with the passed attributes.
85
     *
86
     * @param array       $row  The attributes of the entity to delete
87
     * @param string|null $name The name of the prepared statement that has to be executed
88
     *
89
     * @return void
90
     */
91
    protected function deleteInventorySourceItem($row, $name = null)
92
    {
93
        $this->getMsiBunchProcessor()->deleteInventorySourceItem($row, $name);
94
    }
95
}
96