ClearCustomerAddressObserver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
c 0
b 0
f 0
dl 0
loc 64
ccs 0
cts 11
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 2
A __construct() 0 3 1
A deleteCustomerAddress() 0 3 1
A getCustomerAddressBunchProcessor() 0 3 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Observers\ClearCustomerAddressObserver
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2018 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-customer-address
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Address\Observers;
16
17
use TechDivision\Import\Customer\Address\Utils\ColumnKeys;
18
use TechDivision\Import\Customer\Address\Utils\MemberNames;
19
use TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface;
20
21
/**
22
 * Observer that removes the customer address with the identifier found in the CSV file.
23
 *
24
 * @author    Tim Wagner <[email protected]>
25
 * @copyright 2018 TechDivision GmbH <[email protected]>
26
 * @license   https://opensource.org/licenses/MIT
27
 * @link      https://github.com/techdivision/import-customer-address
28
 * @link      http://www.techdivision.com
29
 */
30
class ClearCustomerAddressObserver extends AbstractCustomerAddressImportObserver
31
{
32
33
    /**
34
     * The customer address bunch processor instance.
35
     *
36
     * @var \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface
37
     */
38
    protected $customerAddressBunchProcessor;
39
40
    /**
41
     * Initialize the observer with the passed customer bunch processor instance.
42
     *
43
     * @param \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor The customer address bunch processor instance
44
     */
45
    public function __construct(CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor)
46
    {
47
        $this->customerAddressBunchProcessor = $customerAddressBunchProcessor;
48
    }
49
50
    /**
51
     * Return's the customer address bunch processor instance.
52
     *
53
     * @return \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface The customer address bunch processor instance
54
     */
55
    protected function getCustomerAddressBunchProcessor()
56
    {
57
        return $this->customerAddressBunchProcessor;
58
    }
59
60
    /**
61
     * Process the observer's business logic.
62
     *
63
     * @return array The processed row
64
     */
65
    protected function process()
66
    {
67
68
        // load the entity ID
69
        ;
70
71
        // query whether or not, we've found a new entity ID => means we've found a new customer address
72
        if ($this->isLastEntityId($entityId = $this->getValue(ColumnKeys::ENTITY_ID))) {
73
            return;
74
        }
75
76
        // delete the customer address with the passed entity ID
77
        $this->deleteCustomerAddress(array(MemberNames::ENTITY_ID => $entityId));
78
79
        // flush the cache to remove the deleted customer address (which has previously been cached)
80
        $this->getCustomerAddressBunchProcessor()->cleanUp();
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 deleteCustomerAddress($row, $name = null)
92
    {
93
        $this->getCustomerAddressBunchProcessor()->deleteCustomerAddress($row, $name);
94
    }
95
}
96