Completed
Pull Request — master (#6)
by Tim
06:01
created

VariantSubject::getEavAttributeByAttributeCode()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 0
cts 20
cp 0
rs 8.5125
cc 5
eloc 12
nc 4
nop 1
crap 30

1 Method

Rating   Name   Duplication   Size   Complexity  
A VariantSubject::loadProductSuperLink() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Variant\Subjects\VariantSubject
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-variant
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Variant\Subjects;
22
23
use TechDivision\Import\Utils\RegistryKeys;
24
use TechDivision\Import\Product\Subjects\AbstractProductSubject;
25
26
/**
27
 * A SLSB that handles the process to import product variants.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-product-variant
33
 * @link      http://www.techdivision.com
34
 */
35
class VariantSubject extends AbstractProductSubject
36
{
37
38
    /**
39
     * The ID of the parent product to relate the variant with.
40
     *
41
     * @var integer
42
     */
43
    protected $parentId;
44
45
    /**
46
     * The mapping for the SKUs to the created entity IDs.
47
     *
48
     * @var array
49
     */
50
    protected $skuEntityIdMapping = array();
51
52
    /**
53
     * Intializes the previously loaded global data for exactly one variants.
54
     *
55
     * @return void
56
     * @see \Importer\Csv\Actions\ProductImportAction::prepare()
57
     */
58
    public function setUp()
59
    {
60
61
        // invoke parent method
62
        parent::setUp();
63
64
        // load the entity manager and the registry processor
65
        $registryProcessor = $this->getRegistryProcessor();
66
67
        // load the status of the actual import process
68
        $status = $registryProcessor->getAttribute($this->getSerial());
69
70
        // load the attribute set we've prepared intially
71
        $this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING];
72
    }
73
74
    /**
75
     * Set's the ID of the parent product to relate the variant with.
76
     *
77
     * @param integer $parentId The ID of the parent product
78
     *
79
     * @return void
80
     */
81
    public function setParentId($parentId)
82
    {
83
        $this->parentId = $parentId;
84
    }
85
86
    /**
87
     * Return's the ID of the parent product to relate the variant with.
88
     *
89
     * @return integer The ID of the parent product
90
     */
91
    public function getParentId()
92
    {
93
        return $this->parentId;
94
    }
95
96
    /**
97
     * Return the entity ID for the passed SKU.
98
     *
99
     * @param string $sku The SKU to return the entity ID for
100
     *
101
     * @return integer The mapped entity ID
102
     * @throws \Exception Is thrown if the SKU is not mapped yet
103
     */
104
    public function mapSkuToEntityId($sku)
105
    {
106
107
        // query weather or not the SKU has been mapped
108
        if (isset($this->skuEntityIdMapping[$sku])) {
109
            return $this->skuEntityIdMapping[$sku];
110
        }
111
112
        // throw an exception if the SKU has not been mapped yet
113
        throw new \Exception(sprintf('Found not mapped SKU %s', $sku));
114
    }
115
116
    /**
117
     * Return's the store for the passed store code.
118
     *
119
     * @param string $storeCode The store code to return the store for
120
     *
121
     * @return array The requested store
122
     * @throws \Exception Is thrown, if the requested store is not available
123
     */
124
    public function getStoreByStoreCode($storeCode)
125
    {
126
127
        // query whether or not the store with the passed store code exists
128
        if (isset($this->stores[$storeCode])) {
129
            return $this->stores[$storeCode];
130
        }
131
132
        // throw an exception, if not
133
        throw new \Exception(sprintf('Found invalid store code %s', $storeCode));
134
    }
135
136
    /**
137
     * Load's the product relation with the passed parent/child ID.
138
     *
139
     * @param integer $parentId The entity ID of the product relation's parent product
140
     * @param integer $childId  The entity ID of the product relation's child product
141
     *
142
     * @return array The product relation
143
     */
144
    public function loadProductRelation($parentId, $childId)
145
    {
146
        return $this->getProductProcessor()->loadProductRelation($parentId, $childId);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method loadProductRelation() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
147
    }
148
149
    /**
150
     * Load's the product super link with the passed product/parent ID.
151
     *
152
     * @param integer $productId The entity ID of the product super link's product
153
     * @param integer $parentId  The entity ID of the product super link's parent product
154
     *
155
     * @return array The product super link
156
     */
157
    public function loadProductSuperLink($productId, $parentId)
158
    {
159
        return $this->getProductProcessor()->loadProductSuperLink($productId, $parentId);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method loadProductSuperLink() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
160
    }
161
162
    /**
163
     * Load's the product super attribute with the passed product/attribute ID.
164
     *
165
     * @param integer $productId   The entity ID of the product super attribute's product
166
     * @param integer $attributeId The attribute ID of the product super attributes attribute
167
     *
168
     * @return array The product super attribute
169
     */
170
    public function loadProductSuperAttribute($productId, $attributeId)
171
    {
172
        return $this->getProductProcessor()->loadProductSuperAttribute($productId, $attributeId);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method loadProductSuperAttribute() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
173
    }
174
175
    /**
176
     * Load's the product super attribute label with the passed product super attribute/store ID.
177
     *
178
     * @param integer $productSuperAttributeId The product super attribute ID of the product super attribute label
179
     * @param integer $storeId                 The store ID of the product super attribute label
180
     *
181
     * @return array The product super attribute label
182
     */
183
    public function loadProductSuperAttributeLabel($productSuperAttributeId, $storeId)
184
    {
185
        return $this->getProductProcessor()->loadProductSuperAttributeLabel($productSuperAttributeId, $storeId);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method loadProductSuperAttributeLabel() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
186
    }
187
188
    /**
189
     * Persist's the passed product relation data and return's the ID.
190
     *
191
     * @param array $productRelation The product relation data to persist
192
     *
193
     * @return void
194
     */
195
    public function persistProductRelation($productRelation)
196
    {
197
        return $this->getProductProcessor()->persistProductRelation($productRelation);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method persistProductRelation() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
198
    }
199
200
    /**
201
     * Persist's the passed product super link data and return's the ID.
202
     *
203
     * @param array $productSuperLink The product super link data to persist
204
     *
205
     * @return void
206
     */
207
    public function persistProductSuperLink($productSuperLink)
208
    {
209
        return $this->getProductProcessor()->persistProductSuperLink($productSuperLink);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method persistProductSuperLink() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
210
    }
211
212
    /**
213
     * Persist's the passed product super attribute data and return's the ID.
214
     *
215
     * @param array $productSuperAttribute The product super attribute data to persist
216
     *
217
     * @return string The ID of the persisted product super attribute entity
218
     */
219
    public function persistProductSuperAttribute($productSuperAttribute)
220
    {
221
        return $this->getProductProcessor()->persistProductSuperAttribute($productSuperAttribute);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method persistProductSuperAttribute() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
222
    }
223
224
    /**
225
     * Persist's the passed product super attribute label data and return's the ID.
226
     *
227
     * @param array $productSuperAttributeLabel The product super attribute label data to persist
228
     *
229
     * @return void
230
     */
231
    public function persistProductSuperAttributeLabel($productSuperAttributeLabel)
232
    {
233
        return $this->getProductProcessor()->persistProductSuperAttributeLabel($productSuperAttributeLabel);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface TechDivision\Import\Prod...oductProcessorInterface as the method persistProductSuperAttributeLabel() does only exist in the following implementations of said interface: TechDivision\Import\Prod...ProductVariantProcessor.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
234
    }
235
}
236