Completed
Pull Request — master (#5)
by Tim
02:21
created

AttributeBunchProcessor::persistCatalogAttribute()   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 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Services\AttributeBunchProcessor
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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Services;
22
23
use TechDivision\Import\Attribute\Actions\AttributeAction;
24
use TechDivision\Import\Attribute\Actions\AttributeLabelAction;
25
use TechDivision\Import\Attribute\Actions\AttributeOptionAction;
26
use TechDivision\Import\Attribute\Actions\AttributeOptionValueAction;
27
use TechDivision\Import\Attribute\Actions\AttributeOptionSwatchAction;
28
use TechDivision\Import\Attribute\Actions\CatalogAttributeAction;
29
use TechDivision\Import\Attribute\Actions\EntityAttributeAction;
30
use TechDivision\Import\Attribute\Repositories\AttributeRepository;
31
use TechDivision\Import\Attribute\Repositories\AttributeLabelRepository;
32
use TechDivision\Import\Attribute\Repositories\AttributeOptionRepository;
33
use TechDivision\Import\Attribute\Repositories\AttributeOptionValueRepository;
34
use TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository;
35
use TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository;
36
use TechDivision\Import\Attribute\Repositories\EntityAttributeRepository;
37
38
/**
39
 * The attribute bunch processor implementation.
40
 *
41
 * @author    Tim Wagner <[email protected]>
42
 * @copyright 2016 TechDivision GmbH <[email protected]>
43
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
44
 * @link      https://github.com/techdivision/import-attribute
45
 * @link      http://www.techdivision.com
46
 */
47
class AttributeBunchProcessor implements AttributeBunchProcessorInterface
48
{
49
50
    /**
51
     * A PDO connection initialized with the values from the Doctrine EntityManager.
52
     *
53
     * @var \PDO
54
     */
55
    protected $connection;
56
57
    /**
58
     * The attribute repository instance.
59
     *
60
     * @var \TechDivision\Import\Attribute\Repositories\AttributeRepository
61
     */
62
    protected $attributeRepository;
63
64
    /**
65
     * The attribute label repository instance.
66
     *
67
     * @var \TechDivision\Import\Attribute\Repositories\AttributeLabelRepository
68
     */
69
    protected $attributeLabelRepository;
70
71
    /**
72
     * The attribute option repository instance.
73
     *
74
     * @var \TechDivision\Import\Attribute\Repositories\AttributeOptionRepository
75
     */
76
    protected $attributeOptionRepository;
77
78
    /**
79
     * The attribute option value repository instance.
80
     *
81
     * @var \TechDivision\Import\Attribute\Repositories\AttributeOptionValueRepository
82
     */
83
    protected $attributeOptionValueRepository;
84
85
    /**
86
     * The attribute option swatch repository instance.
87
     *
88
     * @var \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository
89
     */
90
    protected $attributeOptionSwatchRepository;
91
92
    /**
93
     * The catalog attribute repository instance.
94
     *
95
     * @var \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository
96
     */
97
    protected $catalogAttributeRepository;
98
99
    /**
100
     * The entity attribute repository instance.
101
     *
102
     * @var \TechDivision\Import\Attribute\Repositories\EntityAttributeRepository
103
     */
104
    protected $entityAttributeRepository;
105
106
    /**
107
     * The attribute action instance.
108
     *
109
     * @var \TechDivision\Import\Attribute\Actions\AttributeAction
110
     */
111
    protected $attributeAction;
112
113
    /**
114
     * The attribute label action instance.
115
     *
116
     * @var \TechDivision\Import\Attribute\Actions\AttributeLabelAction
117
     */
118
    protected $attributeLabelAction;
119
120
    /**
121
     * The attribute option action instance.
122
     *
123
     * @var \TechDivision\Import\Attribute\Actions\AttributeOptionAction
124
     */
125
    protected $attributeOptionAction;
126
127
    /**
128
     * The attribute option value action instance.
129
     *
130
     * @var \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction
131
     */
132
    protected $attributeOptionValueAction;
133
134
    /**
135
     * The attribute option swatch action instance.
136
     *
137
     * @var \TechDivision\Import\Attribute\Actions\AttributeOptionSwatchAction
138
     */
139
    protected $attributeOptionSwatchAction;
140
141
    /**
142
     * The attribute action instance.
143
     *
144
     * @var \TechDivision\Import\Attribute\Actions\CatalogAttributeAction
145
     */
146
    protected $catalogAttributeAction;
147
148
    /**
149
     * The entity attribute action instance.
150
     *
151
     * @var \TechDivision\Import\Attribute\Actions\EntityAttributeAction
152
     */
153
    protected $entityAttributeAction;
154
155
    /**
156
     * Initialize the processor with the necessary assembler and repository instances.
157
     *
158
     * @param \PDO                                                                        $connection                      The PDO connection to use
159
     * @param \TechDivision\Import\Attribute\Repositories\AttributeRepository             $attributeRepository             The attribute repository instance
160
     * @param \TechDivision\Import\Attribute\Repositories\AttributeLabelRepository        $attributeLabelRepository        The attribute label repository instance
161
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionRepository       $attributeOptionRepository       The attribute repository instance
162
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionValueRepository  $attributeOptionValueRepository  The attribute repository value instance
163
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository $attributeOptionSwatchRepository The attribute repository swatch instance
164
     * @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository      $catalogAttributeRepository      The catalog attribute repository instance
165
     * @param \TechDivision\Import\Attribute\Repositories\EntityAttributeRepository       $entityAttributeRepository       The entity attribute repository instance
166
     * @param \TechDivision\Import\Attribute\Actions\AttributeAction                      $attributeAction                 The attribute action instance
167
     * @param \TechDivision\Import\Attribute\Actions\AttributeLabelAction                 $attributeLabelAction            The attribute label action instance
168
     * @param \TechDivision\Import\Attribute\Actions\AttributeOptionAction                $attributeOptionAction           The attribute option action instance
169
     * @param \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction           $attributeOptionValueAction      The attribute option value action instance
170
     * @param \TechDivision\Import\Attribute\Actions\AttributeOptionSwatchAction          $attributeOptionSwatchAction     The attribute option swatch action instance
171
     * @param \TechDivision\Import\Attribute\Actions\CatalogAttributeAction               $catalogAttributeAction          The catalog attribute action instance
172
     * @param \TechDivision\Import\Attribute\Actions\EntityAttributeAction                $entityAttributeAction           The entity attribute action instance
173
     */
174
    public function __construct(
175
        \PDO $connection,
176
        AttributeRepository $attributeRepository,
177
        AttributeLabelRepository $attributeLabelRepository,
178
        AttributeOptionRepository $attributeOptionRepository,
179
        AttributeOptionValueRepository $attributeOptionValueRepository,
180
        AttributeOptionSwatchRepository $attributeOptionSwatchRepository,
181
        CatalogAttributeRepository $catalogAttributeRepository,
182
        EntityAttributeRepository $entityAttributeRepository,
183
        AttributeAction $attributeAction,
184
        AttributeLabelAction $attributeLabelAction,
185
        AttributeOptionAction $attributeOptionAction,
186
        AttributeOptionValueAction $attributeOptionValueAction,
187
        AttributeOptionSwatchAction $attributeOptionSwatchAction,
188
        CatalogAttributeAction $catalogAttributeAction,
189
        EntityAttributeAction $entityAttributeAction
190
    ) {
191
        $this->setConnection($connection);
192
        $this->setAttributeRepository($attributeRepository);
193
        $this->setAttributeLabelRepository($attributeLabelRepository);
194
        $this->setAttributeOptionRepository($attributeOptionRepository);
195
        $this->setAttributeOptionValueRepository($attributeOptionValueRepository);
196
        $this->setAttributeOptionSwatchRepository($attributeOptionSwatchRepository);
197
        $this->setCatalogAttributeRepository($catalogAttributeRepository);
198
        $this->setEntityAttributeRepository($entityAttributeRepository);
199
        $this->setAttributeAction($attributeAction);
200
        $this->setAttributeLabelAction($attributeLabelAction);
201
        $this->setAttributeOptionAction($attributeOptionAction);
202
        $this->setAttributeOptionValueAction($attributeOptionValueAction);
203
        $this->setAttributeOptionSwatchAction($attributeOptionSwatchAction);
204
        $this->setCatalogAttributeAction($catalogAttributeAction);
205
        $this->setEntityAttributeAction($entityAttributeAction);
206
    }
207
208
    /**
209
     * Set's the passed connection.
210
     *
211
     * @param \PDO $connection The connection to set
212
     *
213
     * @return void
214
     */
215
    public function setConnection(\PDO $connection)
216
    {
217
        $this->connection = $connection;
218
    }
219
220
    /**
221
     * Return's the connection.
222
     *
223
     * @return \PDO The connection instance
224
     */
225
    public function getConnection()
226
    {
227
        return $this->connection;
228
    }
229
230
    /**
231
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
232
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
233
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
234
     * to autocommit mode.
235
     *
236
     * @return boolean Returns TRUE on success or FALSE on failure
237
     * @link http://php.net/manual/en/pdo.begintransaction.php
238
     */
239
    public function beginTransaction()
240
    {
241
        return $this->connection->beginTransaction();
242
    }
243
244
    /**
245
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
246
     * ProductProcessor::beginTransaction() starts a new transaction.
247
     *
248
     * @return boolean Returns TRUE on success or FALSE on failure
249
     * @link http://php.net/manual/en/pdo.commit.php
250
     */
251
    public function commit()
252
    {
253
        return $this->connection->commit();
254
    }
255
256
    /**
257
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
258
     *
259
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
260
     * rolled back the transaction.
261
     *
262
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
263
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
264
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
265
     *
266
     * @return boolean Returns TRUE on success or FALSE on failure
267
     * @link http://php.net/manual/en/pdo.rollback.php
268
     */
269
    public function rollBack()
270
    {
271
        return $this->connection->rollBack();
272
    }
273
274
    /**
275
     * Set's the attribute repository instance.
276
     *
277
     * @param \TechDivision\Import\Attribute\Repositories\AttributeRepository $attributeRepository The attribute repository instance
278
     *
279
     * @return void
280
     */
281
    public function setAttributeRepository(AttributeRepository $attributeRepository)
282
    {
283
        $this->attributeRepository = $attributeRepository;
284
    }
285
286
    /**
287
     * Return's the attribute repository instance.
288
     *
289
     * @return \TechDivision\Import\Attribute\Repositories\AttributeRepository The attribute repository instance
290
     */
291
    public function getAttributeRepository()
292
    {
293
        return $this->attributeRepository;
294
    }
295
296
    /**
297
     * Set's the attribute label repository instance.
298
     *
299
     * @param \TechDivision\Import\Attribute\Repositories\AttributeLabelRepository $attributeLabelRepository The attribute label repository instance
300
     *
301
     * @return void
302
     */
303
    public function setAttributeLabelRepository(AttributeLabelRepository $attributeLabelRepository)
304
    {
305
        $this->attributeLabelRepository = $attributeLabelRepository;
306
    }
307
308
    /**
309
     * Return's the attribute label repository instance.
310
     *
311
     * @return \TechDivision\Import\Attribute\Repositories\AttributeRepository The attribute label repository instance
312
     */
313
    public function getAttributeLabelRepository()
314
    {
315
        return $this->attributeLabelRepository;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->attributeLabelRepository; (TechDivision\Import\Attr...ttributeLabelRepository) is incompatible with the return type declared by the interface TechDivision\Import\Attr...ttributeLabelRepository of type TechDivision\Import\Attr...ies\AttributeRepository.

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...
316
    }
317
318
    /**
319
     * Set's the attribute option repository instance.
320
     *
321
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionRepository $attributeOptionRepository The attribute option repository instance
322
     *
323
     * @return void
324
     */
325
    public function setAttributeOptionRepository(AttributeOptionRepository $attributeOptionRepository)
326
    {
327
        $this->attributeOptionRepository = $attributeOptionRepository;
328
    }
329
330
    /**
331
     * Return's the attribute option repository instance.
332
     *
333
     * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionRepository The attribute option repository instance
334
     */
335
    public function getAttributeOptionRepository()
336
    {
337
        return $this->attributeOptionRepository;
338
    }
339
340
    /**
341
     * Set's the attribute option value repository instance.
342
     *
343
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionValueRepository $attributeOptionValueRepository The attribute option value repository instance
344
     *
345
     * @return void
346
     */
347
    public function setAttributeOptionValueRepository(AttributeOptionValueRepository $attributeOptionValueRepository)
348
    {
349
        $this->attributeOptionValueRepository = $attributeOptionValueRepository;
350
    }
351
352
    /**
353
     * Return's the attribute option value repository instance.
354
     *
355
     * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionValueRepository The attribute option value repository instance
356
     */
357
    public function getAttributeOptionValueRepository()
358
    {
359
        return $this->attributeOptionValueRepository;
360
    }
361
362
    /**
363
     * Set's the attribute option swatch repository instance.
364
     *
365
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository $attributeOptionSwatchRepository The attribute option swatch repository instance
366
     *
367
     * @return void
368
     */
369
    public function setAttributeOptionSwatchRepository(AttributeOptionSwatchRepository $attributeOptionSwatchRepository)
370
    {
371
        $this->attributeOptionSwatchRepository = $attributeOptionSwatchRepository;
372
    }
373
374
    /**
375
     * Return's the attribute option swatch repository instance.
376
     *
377
     * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepository The attribute option swatch repository instance
378
     */
379
    public function getAttributeOptionSwatchRepository()
380
    {
381
        return $this->attributeOptionSwatchRepository;
382
    }
383
384
    /**
385
     * Set's the catalog attribute repository instance.
386
     *
387
     * @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository $catalogAttributeRepository The catalog attribute repository instance
388
     *
389
     * @return void
390
     */
391
    public function setCatalogAttributeRepository(CatalogAttributeRepository $catalogAttributeRepository)
392
    {
393
        $this->catalogAttributeRepository = $catalogAttributeRepository;
394
    }
395
396
    /**
397
     * Return's the catalog attribute repository instance.
398
     *
399
     * @return \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepository The catalog attribute repository instance
400
     */
401
    public function getCatalogAttributeRepository()
402
    {
403
        return $this->catalogAttributeRepository;
404
    }
405
406
    /**
407
     * Set's the entity attribute repository instance.
408
     *
409
     * @param \TechDivision\Import\Attribute\Repositories\EntityAttributeRepository $entityAttributeRepository The entity attribute repository instance
410
     *
411
     * @return void
412
     */
413
    public function setEntityAttributeRepository(EntityAttributeRepository $entityAttributeRepository)
414
    {
415
        $this->entityAttributeRepository = $entityAttributeRepository;
416
    }
417
418
    /**
419
     * Return's the entity attribute repository instance.
420
     *
421
     * @return \TechDivision\Import\Attribute\Repositories\EntityAttributeRepository The entity attribute repository instance
422
     */
423
    public function getEntityAttributeRepository()
424
    {
425
        return $this->entityAttributeRepository;
426
    }
427
428
    /**
429
     * Set's the attribute action instance.
430
     *
431
     * @param \TechDivision\Import\Attribute\Actions\AttributeAction $attributeAction The attribute action instance
432
     *
433
     * @return void
434
     */
435
    public function setAttributeAction(AttributeAction $attributeAction)
436
    {
437
        $this->attributeAction = $attributeAction;
438
    }
439
440
    /**
441
     * Return's the attribute action instance.
442
     *
443
     * @return \TechDivision\Import\Attribute\Actions\AttributeAction The attribute action instance
444
     */
445
    public function getAttributeAction()
446
    {
447
        return $this->attributeAction;
448
    }
449
450
    /**
451
     * Set's the attribute label action instance.
452
     *
453
     * @param \TechDivision\Import\Attribute\Actions\AttributeLabelAction $attributeLabelAction The attribute label action instance
454
     *
455
     * @return void
456
     */
457
    public function setAttributeLabelAction(AttributeLabelAction $attributeLabelAction)
458
    {
459
        $this->attributeLabelAction = $attributeLabelAction;
460
    }
461
462
    /**
463
     * Return's the attribute label action instance.
464
     *
465
     * @return \TechDivision\Import\Attribute\Actions\AttributeAction The attribute label action instance
466
     */
467
    public function getAttributeLabelAction()
468
    {
469
        return $this->attributeLabelAction;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->attributeLabelAction; (TechDivision\Import\Attr...ns\AttributeLabelAction) is incompatible with the return type declared by the interface TechDivision\Import\Attr...getAttributeLabelAction of type TechDivision\Import\Attr...Actions\AttributeAction.

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...
470
    }
471
472
    /**
473
     * Set's the attribute option action instance.
474
     *
475
     * @param \TechDivision\Import\Attribute\Actions\AttributeOptionAction $attributeOptionAction The attribute option action instance
476
     *
477
     * @return void
478
     */
479
    public function setAttributeOptionAction(AttributeOptionAction $attributeOptionAction)
480
    {
481
        $this->attributeOptionAction = $attributeOptionAction;
482
    }
483
484
    /**
485
     * Return's the attribute option action instance.
486
     *
487
     * @return \TechDivision\Import\Attribute\Actions\AttributeOptionAction The attribute option action instance
488
     */
489
    public function getAttributeOptionAction()
490
    {
491
        return $this->attributeOptionAction;
492
    }
493
494
    /**
495
     * Set's the attribute option value action instance.
496
     *
497
     * @param \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction $attributeOptionValueAction The attribute option value action instance
498
     *
499
     * @return void
500
     */
501
    public function setAttributeOptionValueAction(AttributeOptionValueAction $attributeOptionValueAction)
502
    {
503
        $this->attributeOptionValueAction = $attributeOptionValueAction;
504
    }
505
506
    /**
507
     * Return's the attribute option value action instance.
508
     *
509
     * @return \TechDivision\Import\Attribute\Actions\AttributeOptionValueAction The attribute option value action instance
510
     */
511
    public function getAttributeOptionValueAction()
512
    {
513
        return $this->attributeOptionValueAction;
514
    }
515
516
    /**
517
     * Set's the attribute option swatch action instance.
518
     *
519
     * @param \TechDivision\Import\Attribute\Actions\AttributeOptionSwatchAction $attributeOptionSwatchAction The attribute option swatch action instance
520
     *
521
     * @return void
522
     */
523
    public function setAttributeOptionSwatchAction(AttributeOptionSwatchAction $attributeOptionSwatchAction)
524
    {
525
        $this->attributeOptionSwatchAction = $attributeOptionSwatchAction;
526
    }
527
528
    /**
529
     * Return's the attribute option swatch action instance.
530
     *
531
     * @return \TechDivision\Import\Attribute\Actions\AttributeOptionSwatchAction The attribute option swatch action instance
532
     */
533
    public function getAttributeOptionSwatchAction()
534
    {
535
        return $this->attributeOptionSwatchAction;
536
    }
537
538
    /**
539
     * Set's the catalog attribute action instance.
540
     *
541
     * @param \TechDivision\Import\Attribute\Actions\CatalogAttributeAction $catalogAttributeAction The catalog attribute action instance
542
     *
543
     * @return void
544
     */
545
    public function setCatalogAttributeAction(CatalogAttributeAction $catalogAttributeAction)
546
    {
547
        $this->catalogAttributeAction = $catalogAttributeAction;
548
    }
549
550
    /**
551
     * Return's the catalog attribute action instance.
552
     *
553
     * @return \TechDivision\Import\Attribute\Actions\CatalogAttributeAction The catalog attribute action instance
554
     */
555
    public function getCatalogAttributeAction()
556
    {
557
        return $this->catalogAttributeAction;
558
    }
559
560
    /**
561
     * Set's the entity attribute action instance.
562
     *
563
     * @param \TechDivision\Import\Attribute\Actions\EntityAttributeAction $entityAttributeAction The entity attribute action instance
564
     *
565
     * @return void
566
     */
567
    public function setEntityAttributeAction(EntityAttributeAction $entityAttributeAction)
568
    {
569
        $this->entityAttributeAction = $entityAttributeAction;
570
    }
571
572
    /**
573
     * Return's the entity attribute action instance.
574
     *
575
     * @return \TechDivision\Import\Attribute\Actions\EntityAttributeAction The entity attribute action instance
576
     */
577
    public function getEntityAttributeAction()
578
    {
579
        return $this->entityAttributeAction;
580
    }
581
582
    /**
583
     * Load's and return's the EAV attribute with the passed code.
584
     *
585
     * @param string $attributeCode The code of the EAV attribute to load
586
     *
587
     * @return array The EAV attribute
588
     */
589
    public function loadAttributeByAttributeCode($attributeCode)
590
    {
591
        return $this->getAttributeRepository()->findOneByAttributeCode($attributeCode);
592
    }
593
594
    /**
595
     * Return's the EAV attribute label with the passed attribute code and store ID.
596
     *
597
     * @param string  $attributeCode The attribute code of the EAV attribute label to return
598
     * @param integer $storeId       The store ID of the EAV attribute label to return
599
     *
600
     * @return array The EAV attribute label
601
     */
602
    public function loadAttributeLabelByAttributeCodeAndStoreId($attributeCode, $storeId)
603
    {
604
        return $this->getAttributeLabelRepository()->findOneByAttributeCodeAndStoreId($attributeCode, $storeId);
605
    }
606
607
    /**
608
     * Load's and return's the EAV attribute option with the passed code, store ID and value.
609
     *
610
     * @param string  $attributeCode The code of the EAV attribute option to load
611
     * @param integer $storeId       The store ID of the attribute option to load
612
     * @param string  $value         The value of the attribute option to load
613
     *
614
     * @return array The EAV attribute option
615
     */
616
    public function loadAttributeOptionByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value)
617
    {
618
        return $this->getAttributeOptionRepository()->findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value);
619
    }
620
621
    /**
622
     * Load's and return's the EAV attribute option value with the passed code, store ID and value.
623
     *
624
     * @param string  $attributeCode The code of the EAV attribute option to load
625
     * @param integer $storeId       The store ID of the attribute option to load
626
     * @param string  $value         The value of the attribute option to load
627
     *
628
     * @return array The EAV attribute option value
629
     */
630
    public function loadAttributeOptionValueByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value)
631
    {
632
        return $this->getAttributeOptionValueRepository()->findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value);
633
    }
634
635
    /**
636
     * Load's and return's the EAV attribute option swatch with the passed code, store ID, value and type.
637
     *
638
     * @param string  $attributeCode The code of the EAV attribute option swatch to load
639
     * @param integer $storeId       The store ID of the attribute option swatch to load
640
     * @param string  $value         The value of the attribute option swatch to load
641
     * @param string  $type          The type of the attribute option swatch to load
642
     *
643
     * @return array The EAV attribute option swatch
644
     */
645
    public function loadAttributeOptionSwatchByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value, $type)
646
    {
647
        return $this->getAttributeOptionSwatchRepository()->findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value, $type);
648
    }
649
650
    /**
651
     * Load's and retur's the EAV catalog attribute with the passed ID.
652
     *
653
     * @param string $attributeId The ID of the EAV catalog attribute to return
654
     *
655
     * @return array The EAV catalog attribute
656
     */
657
    public function loadCatalogAttribute($attributeId)
658
    {
659
        return $this->getCatalogAttributeRepository()->load($attributeId);
660
    }
661
662
    /**
663
     * Return's the EAV entity attribute with the passed entity type, attribute, attribute set and attribute group ID.
664
     *
665
     * @param integer $entityTypeId     The ID of the EAV entity attribute's entity type to return
666
     * @param integer $attributeId      The ID of the EAV entity attribute's attribute to return
667
     * @param integer $attributeSetId   The ID of the EAV entity attribute's attribute set to return
668
     * @param integer $attributeGroupId The ID of the EAV entity attribute's attribute group to return
669
     *
670
     * @return array The EAV entity attribute
671
     */
672
    public function loadEntityAttributeByEntityTypeAndAttributeIdAndAttributeSetIdAndAttributeGroupId($entityTypeId, $attributeId, $attributeSetId, $attributeGroupId)
673
    {
674
        return $this->getEntityAttributeRepository()->findOneByEntityTypeAndAttributeIdAndAttributeSetIdAndAttributeGroupId($entityTypeId, $attributeId, $attributeSetId, $attributeGroupId);
675
    }
676
677
    /**
678
     * Persist's the passed EAV attribute data and return's the ID.
679
     *
680
     * @param array       $attribute The attribute data to persist
681
     * @param string|null $name      The name of the prepared statement that has to be executed
682
     *
683
     * @return string The ID of the persisted attribute
684
     */
685
    public function persistAttribute(array $attribute, $name = null)
686
    {
687
        return $this->getAttributeAction()->persist($attribute, $name);
0 ignored issues
show
Unused Code introduced by
The call to AttributeAction::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...
688
    }
689
690
    /**
691
     * Persist the passed attribute label.
692
     *
693
     * @param array       $attributeLabel The attribute label to persist
694
     * @param string|null $name           The name of the prepared statement that has to be executed
695
     *
696
     * @return void
697
     */
698
    public function persistAttributeLabel(array $attributeLabel, $name = null)
699
    {
700
        $this->getAttributeLabelAction()->persist($attributeLabel, $name);
0 ignored issues
show
Unused Code introduced by
The call to AttributeLabelAction::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...
701
    }
702
703
    /**
704
     * Persist's the passed EAV attribute option data and return's the ID.
705
     *
706
     * @param array       $attributeOption The attribute option data to persist
707
     * @param string|null $name            The name of the prepared statement that has to be executed
708
     *
709
     * @return string The ID of the persisted attribute
710
     */
711
    public function persistAttributeOption(array $attributeOption, $name = null)
712
    {
713
        return $this->getAttributeOptionAction()->persist($attributeOption, $name);
0 ignored issues
show
Unused Code introduced by
The call to AttributeOptionAction::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...
714
    }
715
716
    /**
717
     * Persist's the passed EAV attribute option value data and return's the ID.
718
     *
719
     * @param array       $attributeOptionValue The attribute option value data to persist
720
     * @param string|null $name                 The name of the prepared statement that has to be executed
721
     *
722
     * @return void
723
     */
724
    public function persistAttributeOptionValue(array $attributeOptionValue, $name = null)
725
    {
726
        $this->getAttributeOptionValueAction()->persist($attributeOptionValue, $name);
0 ignored issues
show
Unused Code introduced by
The call to AttributeOptionValueAction::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...
727
    }
728
729
    /**
730
     * Persist the passed attribute option swatch.
731
     *
732
     * @param array       $attributeOptionSwatch The attribute option swatch to persist
733
     * @param string|null $name                  The name of the prepared statement that has to be executed
734
     *
735
     * @return void
736
     */
737
    public function persistAttributeOptionSwatch(array $attributeOptionSwatch, $name = null)
738
    {
739
        $this->getAttributeOptionSwatchAction()->persist($attributeOptionSwatch, $name);
0 ignored issues
show
Unused Code introduced by
The call to AttributeOptionSwatchAction::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...
740
    }
741
742
    /**
743
     * Persist's the passed EAV catalog attribute data and return's the ID.
744
     *
745
     * @param array       $catalogAttribute The catalog attribute data to persist
746
     * @param string|null $name             The name of the prepared statement that has to be executed
747
     *
748
     * @return void
749
     */
750
    public function persistCatalogAttribute(array $catalogAttribute, $name = null)
751
    {
752
        $this->getCatalogAttributeAction()->persist($catalogAttribute, $name);
0 ignored issues
show
Unused Code introduced by
The call to CatalogAttributeAction::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...
753
    }
754
755
    /**
756
     * Persist's the passed EAV entity attribute data and return's the ID.
757
     *
758
     * @param array       $entityAttribute The entity attribute data to persist
759
     * @param string|null $name            The name of the prepared statement that has to be executed
760
     *
761
     * @return void
762
     */
763
    public function persistEntityAttribute(array $entityAttribute, $name = null)
764
    {
765
        $this->getEntityAttributeAction()->persist($entityAttribute, $name);
0 ignored issues
show
Unused Code introduced by
The call to EntityAttributeAction::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...
766
    }
767
768
    /**
769
     * Delete's the EAV attribute with the passed attributes.
770
     *
771
     * @param array       $row  The attributes of the EAV attribute to delete
772
     * @param string|null $name The name of the prepared statement that has to be executed
773
     *
774
     * @return void
775
     */
776
    public function deleteAttribute($row, $name = null)
777
    {
778
        $this->getAttributeAction()->delete($row, $name);
779
    }
780
}
781