CleanUpObserver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerBunchProcessor() 0 3 1
A process() 0 15 1
A setLastIdentifier() 0 3 1
A __construct() 0 3 1
A addCustomerIdentifierEntityIdMapping() 0 3 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Observers\CleanUpObserver
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-product
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Observers;
16
17
use TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface;
18
use TechDivision\Import\Customer\Utils\ColumnKeys;
19
20
/**
21
 * An observer implementation that handles the process to import customer bunches.
22
 *
23
 * @author    Tim Wagner <[email protected]>
24
 * @copyright 2018 TechDivision GmbH <[email protected]>
25
 * @license   https://opensource.org/licenses/MIT
26
 * @link      https://github.com/techdivision/import-customer
27
 * @link      http://www.techdivision.com
28
 */
29
class CleanUpObserver extends AbstractCustomerImportObserver
30
{
31
32
    /**
33
     * The customer bunch processor instance.
34
     *
35
     * @var \TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface
36
     */
37
    protected $customerBunchProcessor;
38
39
    /**
40
     * Initialize the observer with the passed customer bunch processor instance.
41
     *
42
     * @param \TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface $customerBunchProcessor The customer bunch processor instance
43
     */
44
    public function __construct(CustomerBunchProcessorInterface $customerBunchProcessor)
45
    {
46
        $this->customerBunchProcessor = $customerBunchProcessor;
47
    }
48
49
    /**
50
     * Return's the customer bunch processor instance.
51
     *
52
     * @return \TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface The customer bunch processor instance
53
     */
54
    protected function getCustomerBunchProcessor()
55
    {
56
        return $this->customerBunchProcessor;
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 email and website code
68
        $email = $this->getValue(ColumnKeys::EMAIL);
69
        $website = $this->getValue(ColumnKeys::WEBSITE);
70
71
        // add the customer identifier => entity ID mapping
72
        $this->addCustomerIdentifierEntityIdMapping($email, $website);
73
74
        // clean-up the repositories etc. to free memory
75
        $this->getCustomerBunchProcessor()->cleanUp();
76
77
        // temporary persist the last customer identifier
78
        $this->setLastIdentifier(array($email, $website));
79
    }
80
81
    /**
82
     * Add the passed mail address/website code => entity ID mapping.
83
     *
84
     * @param string $email   The mail address of the customer
85
     * @param string $website The website code the customer is bound to
86
     *
87
     * @return void
88
     */
89
    public function addCustomerIdentifierEntityIdMapping($email, $website)
90
    {
91
        $this->getSubject()->addCustomerIdentifierEntityIdMapping($email, $website);
92
    }
93
94
    /**
95
     * Sets the customer identifier of the last imported customer.
96
     *
97
     * @param array $identifier The unique customer identifier
98
     *
99
     * @return void
100
     */
101
    protected function setLastIdentifier(array $identifier)
102
    {
103
        $this->getSubject()->setLastIdentifier($identifier);
104
    }
105
}
106