AbstractMsiImportObserver   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 43
ccs 0
cts 7
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 1
A hasSourceBeenProcessed() 0 3 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Observers\AbstractMsiImportObserver
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-msi
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Product\Msi\Observers;
16
17
use TechDivision\Import\Subjects\SubjectInterface;
18
use TechDivision\Import\Observers\AbstractObserver;
19
20
/**
21
 * Abstract observer that handles the process to import MSI inventory source item 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-product-msi
27
 * @link      http://www.techdivision.com
28
 */
29
abstract class AbstractMsiImportObserver extends AbstractObserver implements MsiImportObserverInterface
30
{
31
32
    /**
33
     * Will be invoked by the action on the events the listener has been registered for.
34
     *
35
     * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance
36
     *
37
     * @return array The modified row
38
     * @see \TechDivision\Import\Observers\ObserverInterface::handle()
39
     */
40
    public function handle(SubjectInterface $subject)
41
    {
42
43
        // initialize the row
44
        $this->setSubject($subject);
45
        $this->setRow($subject->getRow());
46
47
        // process the functionality and return the row
48
        $this->process();
49
50
        // return the processed row
51
        return $this->getRow();
52
    }
53
54
    /**
55
     * Process the observer's business logic.
56
     *
57
     * @return void
58
     */
59
    abstract protected function process();
60
61
    /**
62
     * Queries whether or not the SKU/source code has already been processed.
63
     *
64
     * @param string $sku        The SKU to check been processed
65
     * @param string $sourceCode The source code to check been processed
66
     *
67
     * @return boolean TRUE if the SKU/source code has been processed, else FALSE
68
     */
69
    protected function hasSourceBeenProcessed($sku, $sourceCode)
70
    {
71
        return $this->getSubject()->hasSourceBeenProcessed($sku, $sourceCode);
72
    }
73
}
74