storeViewHasBeenProcessed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Observers\AbstractCustomerImportObserver
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
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Customer\Observers;
16
17
use TechDivision\Import\Customer\Utils\ColumnKeys;
18
use TechDivision\Import\Subjects\SubjectInterface;
19
use TechDivision\Import\Observers\AbstractObserver;
20
21
/**
22
 * Abstract category observer that handles the process to import customer bunches.
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
28
 * @link      http://www.techdivision.com
29
 */
30
abstract class AbstractCustomerImportObserver extends AbstractObserver implements CustomerImportObserverInterface
31
{
32
33
    /**
34
     * Will be invoked by the action on the events the listener has been registered for.
35
     *
36
     * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance
37
     *
38
     * @return array The modified row
39
     * @see \TechDivision\Import\Observers\ObserverInterface::handle()
40
     */
41
    public function handle(SubjectInterface $subject)
42
    {
43
44
        // initialize the row
45
        $this->setSubject($subject);
46
        $this->setRow($subject->getRow());
47
48
        // process the functionality and return the row
49
        $this->process();
50
51
        // return the processed row
52
        return $this->getRow();
53
    }
54
55
    /**
56
     * Process the observer's business logic.
57
     *
58
     * @return void
59
     */
60
    abstract protected function process();
61
62
    /**
63
     * Return's the column names that contains the primary key.
64
     *
65
     * @return array the column names that contains the primary key
66
     */
67
    protected function getPrimaryKeyColumnName()
68
    {
69
        return array(ColumnKeys::EMAIL, ColumnKeys::WEBSITE);
70
    }
71
72
    /**
73
     * Queries whether or not the customer with the passed identifier has already been processed.
74
     *
75
     * @param array $identifier The customer identifier to check been processed
76
     *
77
     * @return boolean TRUE if the customer identifier has been processed, else FALSE
78
     */
79
    protected function hasBeenProcessed(array $identifier)
80
    {
81
        return $this->getSubject()->hasBeenProcessed($identifier);
82
    }
83
84
    /**
85
     * Queries whether or not the passed customer identifier and store view code has already been processed.
86
     *
87
     * @param array  $identifier    The customer identifier to check been processed
88
     * @param string $storeViewCode The store view code to check been processed
89
     *
90
     * @return boolean TRUE if the customer with the passed identifier and store view code has been processed, else FALSE
91
     */
92
    protected function storeViewHasBeenProcessed(array $identifier, $storeViewCode)
93
    {
94
        return $this->getSubject()->storeViewHasBeenProcessed($identifier, $storeViewCode);
95
    }
96
97
    /**
98
     * Return's TRUE if the passed customer identifier is the actual one.
99
     *
100
     * @param array $identifier The customer identifier to check
101
     *
102
     * @return boolean TRUE if the passed customer identifier is the actual one
103
     */
104
    protected function isLastIdentifier(array $identifier)
105
    {
106
        return $this->getSubject()->getLastIdentifier() === $identifier;
107
    }
108
}
109