Completed
Push — master ( a9b7ce...a1aea0 )
by Tim
11s
created

getEavAttributeRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Variant\Services\ProductVariantProcessor
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\Services;
22
23
/**
24
 * A SLSB providing methods to load product data using a PDO connection.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import-product-variant
30
 * @link      http://www.techdivision.com
31
 */
32
class ProductVariantProcessor implements ProductVariantProcessorInterface
33
{
34
35
    /**
36
     * A PDO connection initialized with the values from the Doctrine EntityManager.
37
     *
38
     * @var \PDO
39
     */
40
    protected $connection;
41
42
    /**
43
     * The repository to access EAV attribute set.
44
     *
45
     * @var \TechDivision\Import\Product\Repositories\EavAttributeSetRepository
46
     */
47
    protected $eavAttributeSetRepository;
48
49
    /**
50
     * The repository to access product relations.
51
     *
52
     * @var \TechDivision\Import\Product\Repositories\ProductRelationRepository
53
     */
54
    protected $productRelationRepository;
55
56
    /**
57
     * The repository to access product relations.
58
     *
59
     * @var \TechDivision\Import\Product\Repositories\ProductSuperLinkRepository
60
     */
61
    protected $productSuperLinkRepository;
62
63
    /**
64
     * The repository to access product super attributes.
65
     *
66
     * @var \TechDivision\Import\Product\Repositories\ProductSuperAttributeRepository
67
     */
68
    protected $productSuperAttributeRepository;
69
70
    /**
71
     * The repository to access product super attribute labels.
72
     *
73
     * @var \TechDivision\Import\Product\Repositories\ProductSuperAttributeLabelRepository
74
     */
75
    protected $productSuperAttributeLabelRepository;
76
77
    /**
78
     * The repository to access EAV attribute option values.
79
     *
80
     * @var \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository
81
     */
82
    protected $eavAttributeOptionValueRepository;
83
84
    /**
85
     * The action for product relation CRUD methods.
86
     *
87
     * @var \TechDivision\Import\Product\Variant\Actions\ProductRelationAction
88
     */
89
    protected $productRelationAction;
90
91
    /**
92
     * The action for product super attribute CRUD methods.
93
     *
94
     * @var \TechDivision\Import\Product\Variant\Actions\ProductSuperAttributeAction
95
     */
96
    protected $productSuperAttributeAction;
97
98
    /**
99
     * The action for product super attribute label CRUD methods.
100
     *
101
     * @var \TechDivision\Import\Product\Variant\Actions\ProductSuperAttributeLabelAction
102
     */
103
    protected $productSuperAttributeLabelAction;
104
105
    /**
106
     * The action for product super link CRUD methods.
107
     *
108
     * @var \TechDivision\Import\Product\Variant\Actions\ProductSuperLinkAction
109
     */
110
    protected $productSuperLinkAction;
111
112
    /**
113
     * Set's the passed connection.
114
     *
115
     * @param \PDO $connection The connection to set
116
     *
117
     * @return void
118
     */
119
    public function setConnection(\PDO $connection)
120
    {
121
        $this->connection = $connection;
122
    }
123
124
    /**
125
     * Return's the connection.
126
     *
127
     * @return \PDO The connection instance
128
     */
129
    public function getConnection()
130
    {
131
        return $this->connection;
132
    }
133
134
    /**
135
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
136
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
137
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
138
     * to autocommit mode.
139
     *
140
     * @return boolean Returns TRUE on success or FALSE on failure
141
     * @link http://php.net/manual/en/pdo.begintransaction.php
142
     */
143
    public function beginTransaction()
144
    {
145
        return $this->connection->beginTransaction();
146
    }
147
148
    /**
149
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
150
     * ProductProcessor::beginTransaction() starts a new transaction.
151
     *
152
     * @return boolean Returns TRUE on success or FALSE on failure
153
     * @link http://php.net/manual/en/pdo.commit.php
154
     */
155
    public function commit()
156
    {
157
        return $this->connection->commit();
158
    }
159
160
    /**
161
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
162
     *
163
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
164
     * rolled back the transaction.
165
     *
166
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
167
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
168
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
169
     *
170
     * @return boolean Returns TRUE on success or FALSE on failure
171
     * @link http://php.net/manual/en/pdo.rollback.php
172
     */
173
    public function rollBack()
174
    {
175
        return $this->connection->rollBack();
176
    }
177
178
    /**
179
     * Set's the repository to access EAV attributes.
180
     *
181
     * @param \TechDivision\Import\Product\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes
182
     *
183
     * @return void
184
     */
185
    public function setEavAttributeRepository($eavAttributeRepository)
186
    {
187
        $this->eavAttributeRepository = $eavAttributeRepository;
0 ignored issues
show
Bug introduced by
The property eavAttributeRepository does not seem to exist. Did you mean eavAttributeSetRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
188
    }
189
190
    /**
191
     * Return's the repository to access EAV attributes.
192
     *
193
     * @return \TechDivision\Import\Product\Repositories\EavAttributeRepository The repository instance
194
     */
195
    public function getEavAttributeRepository()
196
    {
197
        return $this->eavAttributeRepository;
0 ignored issues
show
Bug introduced by
The property eavAttributeRepository does not seem to exist. Did you mean eavAttributeSetRepository?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
198
    }
199
200
    /**
201
     * Set's the repository to access product relations.
202
     *
203
     * @param \TechDivision\Import\Product\Repositories\ProductRelationRepository $productRelationRepository The repository instance
204
     *
205
     * @return void
206
     */
207
    public function setProductRelationRepository($productRelationRepository)
208
    {
209
        $this->productRelationRepository = $productRelationRepository;
210
    }
211
212
    /**
213
     * Return's the repository to access product relations.
214
     *
215
     * @return \TechDivision\Import\Product\Repositories\ProductRelationRepository The repository instance
216
     */
217
    public function getProductRelationRepository()
218
    {
219
        return $this->productRelationRepository;
220
    }
221
222
    /**
223
     * Set's the repository to access product super links.
224
     *
225
     * @param \TechDivision\Import\Product\Repositories\ProductSuperLinkRepository $productSuperLinkRepository The repository instance
226
     *
227
     * @return void
228
     */
229
    public function setProductSuperLinkRepository($productSuperLinkRepository)
230
    {
231
        $this->productSuperLinkRepository = $productSuperLinkRepository;
232
    }
233
234
    /**
235
     * Return's the repository to access product super links.
236
     *
237
     * @return \TechDivision\Import\Product\Repositories\ProductSuperLinkRepository The repository instance
238
     */
239
    public function getProductSuperLinkRepository()
240
    {
241
        return $this->productSuperLinkRepository;
242
    }
243
244
    /**
245
     * Set's the repository to access product super attributes.
246
     *
247
     * @param \TechDivision\Import\Product\Repositories\ProductSuperAttributeRepository $productSuperAttributeRepository The repository instance
248
     *
249
     * @return void
250
     */
251
    public function setProductSuperAttributeRepository($productSuperAttributeRepository)
252
    {
253
        $this->productSuperAttributeRepository = $productSuperAttributeRepository;
254
    }
255
256
    /**
257
     * Return's the repository to access product super attributes.
258
     *
259
     * @return \TechDivision\Import\Product\Repositories\ProductSuperAttributeRepository The repository instance
260
     */
261
    public function getProductSuperAttributeRepository()
262
    {
263
        return $this->productSuperAttributeRepository;
264
    }
265
266
    /**
267
     * Set's the repository to access product super attribute labels.
268
     *
269
     * @param \TechDivision\Import\Product\Repositories\ProductSuperAttributeLabelRepository $productSuperAttributeLabelRepository The repository instance
270
     *
271
     * @return void
272
     */
273
    public function setProductSuperAttributeLabelRepository($productSuperAttributeLabelRepository)
274
    {
275
        $this->productSuperAttributeLabelRepository = $productSuperAttributeLabelRepository;
276
    }
277
278
    /**
279
     * Return's the repository to access product super attribute labels.
280
     *
281
     * @return \TechDivision\Import\Product\Repositories\ProductSuperAttributLabeleRepository The repository instance
282
     */
283
    public function getProductSuperAttributeLabelRepository()
284
    {
285
        return $this->productSuperAttributeLabelRepository;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->productSup...tributeLabelRepository; (TechDivision\Import\Prod...ttributeLabelRepository) is incompatible with the return type declared by the interface TechDivision\Import\Prod...ttributeLabelRepository of type TechDivision\Import\Prod...ttributLabeleRepository.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
286
    }
287
288
    /**
289
     * Set's the repository to access EAV attribute option values.
290
     *
291
     * @param \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository $eavAttributeOptionValueRepository The repository to access EAV attribute option values
292
     *
293
     * @return void
294
     */
295
    public function setEavAttributeOptionValueRepository($eavAttributeOptionValueRepository)
296
    {
297
        $this->eavAttributeOptionValueRepository = $eavAttributeOptionValueRepository;
298
    }
299
300
    /**
301
     * Return's the repository to access EAV attribute option values.
302
     *
303
     * @return \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository The repository instance
304
     */
305
    public function getEavAttributeOptionValueRepository()
306
    {
307
        return $this->eavAttributeOptionValueRepository;
308
    }
309
310
    /**
311
     * Set's the action with the product relation CRUD methods.
312
     *
313
     * @param \TechDivision\Import\Product\Variant\Actions\ProductRelationAction $productRelationAction The action with the product relation CRUD methods
314
     *
315
     * @return void
316
     */
317
    public function setProductRelationAction($productRelationAction)
318
    {
319
        $this->productRelationAction = $productRelationAction;
320
    }
321
322
    /**
323
     * Return's the action with the product relation CRUD methods.
324
     *
325
     * @return \TechDivision\Import\Product\Variant\Actions\ProductRelationAction The action instance
326
     */
327
    public function getProductRelationAction()
328
    {
329
        return $this->productRelationAction;
330
    }
331
332
    /**
333
     * Set's the action with the product super attribute CRUD methods.
334
     *
335
     * @param \TechDivision\Import\Product\Variant\Actions\ProductSuperAttributeAction $productSuperAttributeAction The action with the product super attribute CRUD methods
336
     *
337
     * @return void
338
     */
339
    public function setProductSuperAttributeAction($productSuperAttributeAction)
340
    {
341
        $this->productSuperAttributeAction = $productSuperAttributeAction;
342
    }
343
344
    /**
345
     * Return's the action with the product super attribute CRUD methods.
346
     *
347
     * @return \TechDivision\Import\Product\Variant\Actions\ProductSuperAttributeAction The action instance
348
     */
349
    public function getProductSuperAttributeAction()
350
    {
351
        return $this->productSuperAttributeAction;
352
    }
353
354
    /**
355
     * Set's the action with the product super attribute label CRUD methods.
356
     *
357
     * @param \TechDivision\Import\Product\Variant\Actions\ProductSuperAttributeLabelAction $productSuperAttributeLabelAction The action with the product super attribute label CRUD methods
358
     *
359
     * @return void
360
     */
361
    public function setProductSuperAttributeLabelAction($productSuperAttributeLabelAction)
362
    {
363
        $this->productSuperAttributeLabelAction = $productSuperAttributeLabelAction;
364
    }
365
366
    /**
367
     * Return's the action with the product super attribute label CRUD methods.
368
     *
369
     * @return \TechDivision\Import\Product\Variant\Actions\ProductSuperAttributeLabelAction The action instance
370
     */
371
    public function getProductSuperAttributeLabelAction()
372
    {
373
        return $this->productSuperAttributeLabelAction;
374
    }
375
376
    /**
377
     * Set's the action with the product super link CRUD methods.
378
     *
379
     * @param \TechDivision\Import\Product\Variant\Actions\ProductSuperLinkAction $productSuperLinkAction The action with the product super link CRUD methods
380
     *
381
     * @return void
382
     */
383
    public function setProductSuperLinkAction($productSuperLinkAction)
384
    {
385
        $this->productSuperLinkAction = $productSuperLinkAction;
386
    }
387
388
    /**
389
     * Return's the action with the product super link CRUD methods.
390
     *
391
     * @return \TechDivision\Import\Product\Variant\Actions\ProductSuperLinkAction The action instance
392
     */
393
    public function getProductSuperLinkAction()
394
    {
395
        return $this->productSuperLinkAction;
396
    }
397
398
    /**
399
     * Return's the attribute option value with the passed value and store ID.
400
     *
401
     * @param mixed   $value   The option value
402
     * @param integer $storeId The ID of the store
403
     *
404
     * @return array|boolean The attribute option value instance
405
     */
406
    public function getEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId)
407
    {
408
        return $this->getEavAttributeOptionValueRepository()->findEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId);
409
    }
410
411
    /**
412
     * Return's the first EAV attribute for the passed option value and store ID.
413
     *
414
     * @param string $optionValue The option value of the EAV attributes
415
     * @param string $storeId     The store ID of the EAV attribues
416
     *
417
     * @return array The array with the EAV attribute
418
     */
419
    public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId)
420
    {
421
        return $this->getEavAttributeRepository()->findOneByOptionValueAndStoreId($optionValue, $storeId);
422
    }
423
424
    /**
425
     * Load's the product relation with the passed parent/child ID.
426
     *
427
     * @param integer $parentId The entity ID of the product relation's parent product
428
     * @param integer $childId  The entity ID of the product relation's child product
429
     *
430
     * @return array The product relation
431
     */
432
    public function loadProductRelation($parentId, $childId)
433
    {
434
        return $this->getProductRelationRepository()->findOneByParentIdAndChildId($parentId, $childId);
435
    }
436
437
    /**
438
     * Load's the product super link with the passed product/parent ID.
439
     *
440
     * @param integer $productId The entity ID of the product super link's product
441
     * @param integer $parentId  The entity ID of the product super link's parent product
442
     *
443
     * @return array The product super link
444
     */
445
    public function loadProductSuperLink($productId, $parentId)
446
    {
447
        return $this->getProductSuperLinkRepository()->findOneByProductIdAndParentId($productId, $parentId);
448
    }
449
450
    /**
451
     * Load's the product super attribute with the passed product/attribute ID.
452
     *
453
     * @param integer $productId   The entity ID of the product super attribute's product
454
     * @param integer $attributeId The attribute ID of the product super attributes attribute
455
     *
456
     * @return array The product super attribute
457
     */
458
    public function loadProductSuperAttribute($productId, $attributeId)
459
    {
460
        return $this->getProductSuperAttributeRepository()->findOneByProductIdAndAttributeId($productId, $attributeId);
461
    }
462
463
    /**
464
     * Load's the product super attribute label with the passed product super attribute/store ID.
465
     *
466
     * @param integer $productSuperAttributeId The product super attribute ID of the product super attribute label
467
     * @param integer $storeId                 The store ID of the product super attribute label
468
     *
469
     * @return array The product super attribute label
470
     */
471
    public function loadProductSuperAttributeLabel($productSuperAttributeId, $storeId)
472
    {
473
        return $this->getProductSuperAttributeLabelRepository()->findOneByProductSuperAttributeIdAndStoreId($productSuperAttributeId, $storeId);
474
    }
475
476
    /**
477
     * Persist's the passed product relation data and return's the ID.
478
     *
479
     * @param array       $productRelation The product relation data to persist
480
     * @param string|null $name            The name of the prepared statement that has to be executed
481
     *
482
     * @return void
483
     */
484
    public function persistProductRelation($productRelation, $name = null)
485
    {
486
        return $this->getProductRelationAction()->persist($productRelation, $name);
487
    }
488
489
    /**
490
     * Persist's the passed product super link data and return's the ID.
491
     *
492
     * @param array       $productSuperLink The product super link data to persist
493
     * @param string|null $name             The name of the prepared statement that has to be executed
494
     *
495
     * @return void
496
     */
497
    public function persistProductSuperLink($productSuperLink, $name = null)
498
    {
499
        return $this->getProductSuperLinkAction()->persist($productSuperLink, $name);
500
    }
501
502
    /**
503
     * Persist's the passed product super attribute data and return's the ID.
504
     *
505
     * @param array       $productSuperAttribute The product super attribute data to persist
506
     * @param string|null $name                  The name of the prepared statement that has to be executed
507
     *
508
     * @return string The ID of the persisted product super attribute entity
509
     */
510
    public function persistProductSuperAttribute($productSuperAttribute, $name = null)
511
    {
512
        return $this->getProductSuperAttributeAction()->persist($productSuperAttribute, $name);
0 ignored issues
show
Unused Code introduced by
The call to ProductSuperAttributeAction::persist() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
513
    }
514
515
    /**
516
     * Persist's the passed product super attribute label data and return's the ID.
517
     *
518
     * @param array       $productSuperAttributeLabel The product super attribute label data to persist
519
     * @param string|null $name                       The name of the prepared statement that has to be executed
520
     *
521
     * @return void
522
     */
523
    public function persistProductSuperAttributeLabel($productSuperAttributeLabel, $name = null)
524
    {
525
        return $this->getProductSuperAttributeLabelAction()->persist($productSuperAttributeLabel, $name);
526
    }
527
}
528