Completed
Push — master ( c2b612...40d106 )
by Tim
9s
created

ClearUrlRewriteObserver::removeUrlRewrite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Observers\PreImport\ClearUrlRewriteObserver
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\PreImport;
22
23
use TechDivision\Import\Product\Utils\ColumnKeys;
24
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
25
use TechDivision\Import\Product\Utils\SqlStatements;
26
27
/**
28
 * A SLSB that handles the process to import product bunches.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import-product
34
 * @link      http://www.techdivision.com
35
 */
36 View Code Duplication
class ClearUrlRewriteObserver extends AbstractProductImportObserver
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
{
38
39
    /**
40
     * Will be invoked by the action on the events the listener has been registered for.
41
     *
42
     * @param array $row The row to handle
43
     *
44
     * @return array The modified row
45
     * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle()
46
     */
47
    public function handle(array $row)
48
    {
49
50
        // load the header information
51
        $headers = $this->getHeaders();
52
53
        // query whether or not, we've found a new SKU => means we've found a new product
54
        if ($this->isLastSku($sku = $row[$headers[ColumnKeys::SKU]])) {
55
            return $row;
56
        }
57
58
        // remove the product with the passed SKU
59
        $this->removeUrlRewrite(array($sku), SqlStatements::REMOVE_URL_REWRITE_BY_SKU);
60
61
        // return the prepared row
62
        return $row;
63
    }
64
65
    /**
66
     * Remove's the entity with the passed attributes.
67
     *
68
     * @param array       $row  The attributes of the entity to remove
69
     * @param string|null $name The name of the prepared statement that has to be executed
70
     *
71
     * @return void
72
     */
73
    public function removeUrlRewrite($row, $name = null)
74
    {
75
        $this->getSubject()->removeUrlRewrite($row, $name);
76
    }
77
}
78