Completed
Pull Request — master (#42)
by Tim
05:26
created

AbstractProductImportObserver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 80
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 1
process() 0 1 ?
A hasBeenProcessed() 0 4 1
A addSkuEntityIdMapping() 0 4 1
A addSkuStoreViewCodeMapping() 0 4 1
A isLastSku() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Observers\AbstractProductImportObserver
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 2016 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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Observers;
22
23
use TechDivision\Import\Observers\AbstractObserver;
24
25
/**
26
 * Abstract category observer that handles the process to import product bunches.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-product
32
 * @link      http://www.techdivision.com
33
 */
34
abstract class AbstractProductImportObserver extends AbstractObserver implements ProductImportObserverInterface
35
{
36
37
    /**
38
     * Will be invoked by the action on the events the listener has been registered for.
39
     *
40
     * @param array $row The row to handle
41
     *
42
     * @return array The modified row
43
     * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle()
44
     */
45 8
    public function handle(array $row)
46
    {
47
48
        // initialize the row
49 8
        $this->setRow($row);
0 ignored issues
show
Bug introduced by
The method setRow() does not seem to exist on object<TechDivision\Impo...tProductImportObserver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
        // process the functionality and return the row
52 8
        $this->process();
53
54
        // return the processed row
55 8
        return $this->getRow();
0 ignored issues
show
Bug introduced by
The method getRow() does not seem to exist on object<TechDivision\Impo...tProductImportObserver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
    }
57
58
    /**
59
     * Process the observer's business logic.
60
     *
61
     * @return void
62
     */
63
    abstract protected function process();
64
65
    /**
66
     * Queries whether or not the SKU has already been processed.
67
     *
68
     * @param string $sku The SKU to check been processed
69
     *
70
     * @return boolean TRUE if the SKU has been processed, else FALSE
71
     */
72 7
    protected function hasBeenProcessed($sku)
73
    {
74 7
        return $this->getSubject()->hasBeenProcessed($sku);
75
    }
76
77
    /**
78
     * Add the passed SKU => entity ID mapping.
79
     *
80
     * @param string $sku The SKU
81
     *
82
     * @return void
83
     */
84
    protected function addSkuEntityIdMapping($sku)
85
    {
86
        $this->getSubject()->addSkuEntityIdMapping($sku);
87
    }
88
89
    /**
90
     * Add the passed SKU => store view code mapping.
91
     *
92
     * @param string $sku           The SKU
93
     * @param string $storeViewCode The store view code
94
     *
95
     * @return void
96
     */
97
    protected function addSkuStoreViewCodeMapping($sku, $storeViewCode)
98
    {
99
        $this->getSubject()->addSkuStoreViewCodeMapping($sku, $storeViewCode);
100
    }
101
102
    /**
103
     * Return's TRUE if the passed SKU is the actual one.
104
     *
105
     * @param string $sku The SKU to check
106
     *
107
     * @return boolean TRUE if the passed SKU is the actual one
108
     */
109 1
    protected function isLastSku($sku)
110
    {
111 1
        return $this->getSubject()->getLastSku() === $sku;
112
    }
113
}
114