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

Magic360GalleryUpdateObserver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 25
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A initializeMagic360Gallery() 0 14 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Magic360\Observers\Magic360GalleryUpdateObserver
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\MemberNames;
25
26
/**
27
 * Observer that creates/updates the magic360 gallery value information.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @author    Bernhard Wick <[email protected]>
31
 * @copyright 2017 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-magic360
34
 * @link      http://www.techdivision.com
35
 */
36
class Magic360GalleryUpdateObserver extends Magic360GalleryObserver
37
{
38
39
    /**
40
     * Initialize the gallery value with the passed attributes and returns an instance.
41
     *
42
     * @param array $attr The product media gallery value attributes
43
     *
44
     * @return array The initialized product media gallery value
45
     */
46
    protected function initializeMagic360Gallery(array $attr)
47
    {
48
        // query whether the product media gallery value already exists or not
49
        if ($entity = $this->getSubject()->loadMagic360Gallery(
50
            $attr[MemberNames::PRODUCT_ID],
51
            $attr[MemberNames::POSITION]
52
        )
53
        ) {
54
            return $this->mergeEntity($entity, $attr);
55
        }
56
57
        // simply return the attributes
58
        return $attr;
59
    }
60
}
61