Completed
Push — master ( 9b3686...89ef78 )
by Bernhard
07:29
created

Magic360GalleryObserver::persistMagic360Gallery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Magic360\Observers\Magic360ImageObserver
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
 * @author    Bernhard Wick <[email protected]>
16
 * @copyright 2017 TechDivision GmbH <[email protected]>
17
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
 * @link      https://github.com/techdivision/import-product-magic360
19
 * @link      http://www.techdivision.com
20
 */
21
22
namespace TechDivision\Import\Product\Magic360\Observers;
23
24
use TechDivision\Import\Product\Magic360\Utils\ColumnKeys;
25
use TechDivision\Import\Product\Magic360\Utils\MemberNames;
26
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
27
28
/**
29
 * Adds the images from within artefacts to the Magic360 tables
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @author    Bernhard Wick <[email protected]>
33
 * @copyright 2017 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-product-magic360
36
 * @link      http://www.techdivision.com
37
 */
38
class Magic360GalleryObserver extends AbstractProductImportObserver
39
{
40
41
    /**
42
     * Process the observer's business logic.
43
     *
44
     * @return array The processed row
45
     *
46
     * @throws \Exception Possible error in non-debug mode
47
     */
48
    protected function process()
49
    {
50
        // extract the parent/child ID as well as the link type code from the row
51
        $sku = $this->getValue(ColumnKeys::SKU);
52
53
        // load parent/child IDs and link type ID
54
        $productId = $this->getSubject()->mapSkuToEntityId($sku);
55
56
        $images360Path = $this->getValue(ColumnKeys::IMAGES_PATH);
57
        $mediaFilePath = $this->getSubject()->getMediaDir();
58
        // iterate the images (if any) and initialize an entity for each one
59
        $images = $this->getSubject()->getFilesystem()->listContents($mediaFilePath . DIRECTORY_SEPARATOR . $images360Path);
60
        if (count($images) > 0) {
61
            $entity = null;
0 ignored issues
show
Unused Code introduced by
$entity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
            $entityId = null;
0 ignored issues
show
Unused Code introduced by
$entityId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
            /**
64
             * @var integer $position
65
             * @var array $image
66
             */
67
            foreach ($images as $position => $image) {
68
                $entity = $this->initializeMagic360Gallery($this->initializeEntity(
69
                    array(
70
                        MemberNames::PRODUCT_ID => $productId,
71
                        MemberNames::POSITION => $position + 1,
72
                        MemberNames::FILE => $images360Path . $image['basename']
73
                    )
74
                ));
75
                $this->persistMagic360Gallery($entity);
76
            }
77
        }
78
    }
79
80
    /**
81
     * Initialize the magic360 gallery with the passed attributes and returns an instance.
82
     *
83
     * @param array $attr The gallery attributes
84
     *
85
     * @return array The initialized gallery
86
     */
87
    protected function initializeMagic360Gallery(array $attr)
88
    {
89
        return $attr;
90
    }
91
92
    /**
93
     * Persists the passed magic360 gallery data and returns the ID.
94
     *
95
     * @param array $magic360Gallery The gallery data to persist
96
     *
97
     * @return string The ID of the persisted entity
98
     */
99
    protected function persistMagic360Gallery($magic360Gallery)
100
    {
101
        return $this->getSubject()->persistMagic360Gallery($magic360Gallery);
102
    }
103
}
104