Completed
Push — 19.x ( 24d584 )
by Tim
02:01
created

AttributeBunchProcessor   F

Complexity

Total Complexity 60

Size/Duplication

Total Lines 895
Duplicated Lines 0 %

Coupling/Cohesion

Components 17
Dependencies 11

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 60
lcom 17
cbo 11
dl 0
loc 895
ccs 0
cts 273
cp 0
rs 3.305
c 0
b 0
f 0

60 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 37 1
A setRawEntityLoader() 0 4 1
A getRawEntityLoader() 0 4 1
A setConnection() 0 4 1
A getConnection() 0 4 1
A beginTransaction() 0 4 1
A commit() 0 4 1
A rollBack() 0 4 1
A setAttributeRepository() 0 4 1
A getAttributeRepository() 0 4 1
A setAttributeLabelRepository() 0 4 1
A getAttributeLabelRepository() 0 4 1
A setAttributeOptionRepository() 0 4 1
A getAttributeOptionRepository() 0 4 1
A setEavAttributeOptionValueRepository() 0 4 1
A getEavAttributeOptionValueRepository() 0 4 1
A setAttributeOptionSwatchRepository() 0 4 1
A getAttributeOptionSwatchRepository() 0 4 1
A setCatalogAttributeRepository() 0 4 1
A getCatalogAttributeRepository() 0 4 1
A setEntityAttributeRepository() 0 4 1
A getEntityAttributeRepository() 0 4 1
A setEntityTypeRepository() 0 4 1
A getEntityTypeRepository() 0 4 1
A setAttributeAction() 0 4 1
A getAttributeAction() 0 4 1
A setAttributeLabelAction() 0 4 1
A getAttributeLabelAction() 0 4 1
A setAttributeOptionAction() 0 4 1
A getAttributeOptionAction() 0 4 1
A setAttributeOptionValueAction() 0 4 1
A getAttributeOptionValueAction() 0 4 1
A setAttributeOptionSwatchAction() 0 4 1
A getAttributeOptionSwatchAction() 0 4 1
A setCatalogAttributeAction() 0 4 1
A getCatalogAttributeAction() 0 4 1
A setEntityAttributeAction() 0 4 1
A getEntityAttributeAction() 0 4 1
A loadRawEntity() 0 4 1
A loadAttributeLabelByEntityTypeIdAndAttributeCodeAndStoreId() 0 4 1
A loadAttributeOptionValueByOptionIdAndStoreId() 0 4 1
A loadAttributeOptionSwatchByOptionIdAndStoreId() 0 4 1
A loadCatalogAttribute() 0 4 1
A loadEntityAttributeByAttributeIdAndAttributeSetId() 0 4 1
A loadEntityAttributeByEntityTypeIdAndAttributeIdAndAttributeSetIdAndAttributeGroupId() 0 4 1
A loadEntityTypeByEntityTypeCode() 0 4 1
A loadAttributeByEntityTypeIdAndAttributeCode() 0 4 1
A loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue() 0 4 1
A loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndType() 0 4 1
A loadAttributeOptionValueByEntityTypeIdAndAttributeCodeAndStoreIdAndValue() 0 4 1
A loadAttributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType() 0 4 1
A loadAttributeOptionByAttributeIdAndHighestSortOrder() 0 4 1
A persistAttribute() 0 4 1
A persistAttributeLabel() 0 4 1
A persistAttributeOption() 0 4 1
A persistAttributeOptionValue() 0 4 1
A persistAttributeOptionSwatch() 0 4 1
A persistCatalogAttribute() 0 4 1
A persistEntityAttribute() 0 4 1
A deleteAttribute() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like AttributeBunchProcessor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AttributeBunchProcessor, and based on these observations, apply Extract Interface, too.

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

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...
355
    }
356
357
    /**
358
     * Set's the attribute option repository instance.
359
     *
360
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionRepositoryInterface $attributeOptionRepository The attribute option repository instance
361
     *
362
     * @return void
363
     */
364
    public function setAttributeOptionRepository(AttributeOptionRepositoryInterface $attributeOptionRepository)
365
    {
366
        $this->attributeOptionRepository = $attributeOptionRepository;
367
    }
368
369
    /**
370
     * Return's the attribute option repository instance.
371
     *
372
     * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionRepositoryInterface The attribute option repository instance
373
     */
374
    public function getAttributeOptionRepository()
375
    {
376
        return $this->attributeOptionRepository;
377
    }
378
379
    /**
380
     * Set's the repository to access EAV attribute option values.
381
     *
382
     * @param \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface $eavAttributeOptionValueRepository The repository to access EAV attribute option values
383
     *
384
     * @return void
385
     */
386
    public function setEavAttributeOptionValueRepository(EavAttributeOptionValueRepositoryInterface $eavAttributeOptionValueRepository)
387
    {
388
        $this->eavAttributeOptionValueRepository = $eavAttributeOptionValueRepository;
389
    }
390
391
    /**
392
     * Return's the repository to access EAV attribute option values.
393
     *
394
     * @return \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface The repository instance
395
     */
396
    public function getEavAttributeOptionValueRepository()
397
    {
398
        return $this->eavAttributeOptionValueRepository;
399
    }
400
401
    /**
402
     * Set's the attribute option swatch repository instance.
403
     *
404
     * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepositoryInterface $attributeOptionSwatchRepository The attribute option swatch repository instance
405
     *
406
     * @return void
407
     */
408
    public function setAttributeOptionSwatchRepository(AttributeOptionSwatchRepositoryInterface $attributeOptionSwatchRepository)
409
    {
410
        $this->attributeOptionSwatchRepository = $attributeOptionSwatchRepository;
411
    }
412
413
    /**
414
     * Return's the attribute option swatch repository instance.
415
     *
416
     * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepositoryInterface The attribute option swatch repository instance
417
     */
418
    public function getAttributeOptionSwatchRepository()
419
    {
420
        return $this->attributeOptionSwatchRepository;
421
    }
422
423
    /**
424
     * Set's the catalog attribute repository instance.
425
     *
426
     * @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepositoryInterface $catalogAttributeRepository The catalog attribute repository instance
427
     *
428
     * @return void
429
     */
430
    public function setCatalogAttributeRepository(CatalogAttributeRepositoryInterface $catalogAttributeRepository)
431
    {
432
        $this->catalogAttributeRepository = $catalogAttributeRepository;
433
    }
434
435
    /**
436
     * Return's the catalog attribute repository instance.
437
     *
438
     * @return \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepositoryInterface The catalog attribute repository instance
439
     */
440
    public function getCatalogAttributeRepository()
441
    {
442
        return $this->catalogAttributeRepository;
443
    }
444
445
    /**
446
     * Set's the entity attribute repository instance.
447
     *
448
     * @param \TechDivision\Import\Attribute\Repositories\EntityAttributeRepositoryInterface $entityAttributeRepository The entity attribute repository instance
449
     *
450
     * @return void
451
     */
452
    public function setEntityAttributeRepository(EntityAttributeRepositoryInterface $entityAttributeRepository)
453
    {
454
        $this->entityAttributeRepository = $entityAttributeRepository;
455
    }
456
457
    /**
458
     * Return's the entity attribute repository instance.
459
     *
460
     * @return \TechDivision\Import\Attribute\Repositories\EntityAttributeRepositoryInterface The entity attribute repository instance
461
     */
462
    public function getEntityAttributeRepository()
463
    {
464
        return $this->entityAttributeRepository;
465
    }
466
467
    /**
468
     * Sets the EAV entity type repository.
469
     *
470
     * @param \TechDivision\Import\Repositories\EavEntityTypeRepositoryInterface $entitTypeRepository The repository instance
471
     *
472
     * @return void
473
     */
474
    public function setEntityTypeRepository(EavEntityTypeRepositoryInterface $entitTypeRepository)
475
    {
476
        $this->entityTypeRepository = $entitTypeRepository;
477
    }
478
479
    /**
480
     * Returns the EAV entity type repository.
481
     *
482
     * @return \TechDivision\Import\Repositories\EavEntityTypeRepositoryInterface The repository instance
483
     */
484
    public function getEntityTypeRepository()
485
    {
486
        return $this->entityTypeRepository;
487
    }
488
489
    /**
490
     * Set's the attribute action instance.
491
     *
492
     * @param \TechDivision\Import\Actions\ActionInterface $attributeAction The attribute action instance
493
     *
494
     * @return void
495
     */
496
    public function setAttributeAction(ActionInterface $attributeAction)
497
    {
498
        $this->attributeAction = $attributeAction;
499
    }
500
501
    /**
502
     * Return's the attribute action instance.
503
     *
504
     * @return \TechDivision\Import\Actions\ActionInterface The attribute action instance
505
     */
506
    public function getAttributeAction()
507
    {
508
        return $this->attributeAction;
509
    }
510
511
    /**
512
     * Set's the attribute label action instance.
513
     *
514
     * @param \TechDivision\Import\Actions\ActionInterface $attributeLabelAction The attribute label action instance
515
     *
516
     * @return void
517
     */
518
    public function setAttributeLabelAction(ActionInterface $attributeLabelAction)
519
    {
520
        $this->attributeLabelAction = $attributeLabelAction;
521
    }
522
523
    /**
524
     * Return's the attribute label action instance.
525
     *
526
     * @return \TechDivision\Import\Actions\ActionInterface The attribute label action instance
527
     */
528
    public function getAttributeLabelAction()
529
    {
530
        return $this->attributeLabelAction;
531
    }
532
533
    /**
534
     * Set's the attribute option action instance.
535
     *
536
     * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionAction The attribute option action instance
537
     *
538
     * @return void
539
     */
540
    public function setAttributeOptionAction(ActionInterface $attributeOptionAction)
541
    {
542
        $this->attributeOptionAction = $attributeOptionAction;
543
    }
544
545
    /**
546
     * Return's the attribute option action instance.
547
     *
548
     * @return \TechDivision\Import\Actions\ActionInterface The attribute option action instance
549
     */
550
    public function getAttributeOptionAction()
551
    {
552
        return $this->attributeOptionAction;
553
    }
554
555
    /**
556
     * Set's the attribute option value action instance.
557
     *
558
     * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionValueAction The attribute option value action instance
559
     *
560
     * @return void
561
     */
562
    public function setAttributeOptionValueAction(ActionInterface $attributeOptionValueAction)
563
    {
564
        $this->attributeOptionValueAction = $attributeOptionValueAction;
565
    }
566
567
    /**
568
     * Return's the attribute option value action instance.
569
     *
570
     * @return \TechDivision\Import\Actions\ActionInterface The attribute option value action instance
571
     */
572
    public function getAttributeOptionValueAction()
573
    {
574
        return $this->attributeOptionValueAction;
575
    }
576
577
    /**
578
     * Set's the attribute option swatch action instance.
579
     *
580
     * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionSwatchAction The attribute option swatch action instance
581
     *
582
     * @return void
583
     */
584
    public function setAttributeOptionSwatchAction(ActionInterface $attributeOptionSwatchAction)
585
    {
586
        $this->attributeOptionSwatchAction = $attributeOptionSwatchAction;
587
    }
588
589
    /**
590
     * Return's the attribute option swatch action instance.
591
     *
592
     * @return \TechDivision\Import\Actions\ActionInterface The attribute option swatch action instance
593
     */
594
    public function getAttributeOptionSwatchAction()
595
    {
596
        return $this->attributeOptionSwatchAction;
597
    }
598
599
    /**
600
     * Set's the catalog attribute action instance.
601
     *
602
     * @param \TechDivision\Import\Actions\ActionInterface $catalogAttributeAction The catalog attribute action instance
603
     *
604
     * @return void
605
     */
606
    public function setCatalogAttributeAction(ActionInterface $catalogAttributeAction)
607
    {
608
        $this->catalogAttributeAction = $catalogAttributeAction;
609
    }
610
611
    /**
612
     * Return's the catalog attribute action instance.
613
     *
614
     * @return \TechDivision\Import\Actions\ActionInterface The catalog attribute action instance
615
     */
616
    public function getCatalogAttributeAction()
617
    {
618
        return $this->catalogAttributeAction;
619
    }
620
621
    /**
622
     * Set's the entity attribute action instance.
623
     *
624
     * @param \TechDivision\Import\Actions\ActionInterface $entityAttributeAction The entity attribute action instance
625
     *
626
     * @return void
627
     */
628
    public function setEntityAttributeAction(ActionInterface $entityAttributeAction)
629
    {
630
        $this->entityAttributeAction = $entityAttributeAction;
631
    }
632
633
    /**
634
     * Return's the entity attribute action instance.
635
     *
636
     * @return \TechDivision\Import\Actions\ActionInterface The entity attribute action instance
637
     */
638
    public function getEntityAttributeAction()
639
    {
640
        return $this->entityAttributeAction;
641
    }
642
643
    /**
644
     * Load's and return's a raw entity without primary key but the mandatory members only and nulled values.
645
     *
646
     * @param string $entityTypeCode The entity type code to return the raw entity for
647
     * @param array  $data           An array with data that will be used to initialize the raw entity with
648
     *
649
     * @return array The initialized entity
650
     */
651
    public function loadRawEntity($entityTypeCode, array $data = array())
652
    {
653
        return $this->getRawEntityLoader()->load($entityTypeCode, $data);
0 ignored issues
show
Unused Code introduced by
The call to LoaderInterface::load() has too many arguments starting with $entityTypeCode.

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...
Bug Best Practice introduced by
The return type of return $this->getRawEnti...entityTypeCode, $data); (ArrayAccess) is incompatible with the return type declared by the interface TechDivision\Import\Attr...nterface::loadRawEntity of type array.

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...
654
    }
655
656
    /**
657
     * Return's the EAV attribute label with the passed attribute code and store ID.
658
     *
659
     * @param integer $entityTypeId  The ID of the EAV entity attribute to return the label for
660
     * @param string  $attributeCode The attribute code of the EAV attribute label to return
661
     * @param integer $storeId       The store ID of the EAV attribute label to return
662
     *
663
     * @return array The EAV attribute label
664
     */
665
    public function loadAttributeLabelByEntityTypeIdAndAttributeCodeAndStoreId($entityTypeId, $attributeCode, $storeId)
666
    {
667
        return $this->getAttributeLabelRepository()->findOneByEntityTypeIdAndAttributeCodeAndStoreId($entityTypeId, $attributeCode, $storeId);
668
    }
669
670
    /**
671
     * Load's and return's the EAV attribute option value with the passed option ID and store ID.
672
     *
673
     * @param string  $optionId The option ID
674
     * @param integer $storeId  The store ID of the attribute option to load
675
     *
676
     * @return array The EAV attribute option value
677
     */
678
    public function loadAttributeOptionValueByOptionIdAndStoreId($optionId, $storeId)
679
    {
680
        return $this->getEavAttributeOptionValueRepository()->findOneByOptionIdAndStoreId($optionId, $storeId);
681
    }
682
683
    /**
684
     * Load's and return's the EAV attribute option swatch with the passed option ID and store ID
685
     *
686
     * @param integer $optionId The option ID of the attribute option swatch to load
687
     * @param integer $storeId  The store ID of the attribute option swatch to load
688
     *
689
     * @return array The EAV attribute option swatch
690
     */
691
    public function loadAttributeOptionSwatchByOptionIdAndStoreId($optionId, $storeId)
692
    {
693
        return $this->getAttributeOptionSwatchRepository()->findOneByOptionIdAndStoreId($optionId, $storeId);
694
    }
695
696
    /**
697
     * Load's and retur's the EAV catalog attribute with the passed ID.
698
     *
699
     * @param string $attributeId The ID of the EAV catalog attribute to return
700
     *
701
     * @return array The EAV catalog attribute
702
     */
703
    public function loadCatalogAttribute($attributeId)
704
    {
705
        return $this->getCatalogAttributeRepository()->load($attributeId);
706
    }
707
708
    /**
709
     * Return's the EAV entity attribute with the passed attribute and attribute set ID.
710
     *
711
     * @param integer $attributeId    The ID of the EAV entity attribute's attribute to return
712
     * @param integer $attributeSetId The ID of the EAV entity attribute's attribute set to return
713
     *
714
     * @return array The EAV entity attribute
715
     */
716
    public function loadEntityAttributeByAttributeIdAndAttributeSetId($attributeId, $attributeSetId)
717
    {
718
        return $this->getEntityAttributeRepository()->findOneByAttributeIdAndAttributeSetId($attributeId, $attributeSetId);
719
    }
720
721
    /**
722
     * Return's the EAV entity attribute with the passed entity type, attribute, attribute set and attribute group ID.
723
     *
724
     * @param integer $entityTypeId     The ID of the EAV entity attribute's entity type to return
725
     * @param integer $attributeId      The ID of the EAV entity attribute's attribute to return
726
     * @param integer $attributeSetId   The ID of the EAV entity attribute's attribute set to return
727
     * @param integer $attributeGroupId The ID of the EAV entity attribute's attribute group to return
728
     *
729
     * @return array The EAV entity attribute
730
     */
731
    public function loadEntityAttributeByEntityTypeIdAndAttributeIdAndAttributeSetIdAndAttributeGroupId($entityTypeId, $attributeId, $attributeSetId, $attributeGroupId)
732
    {
733
        return $this->getEntityAttributeRepository()->findOneByEntityTypeIdAndAttributeIdAndAttributeSetIdAndAttributeGroupId($entityTypeId, $attributeId, $attributeSetId, $attributeGroupId);
734
    }
735
736
    /**
737
     * Return's an EAV entity type with the passed entity type code.
738
     *
739
     * @param string $entityTypeCode The code of the entity type to return
740
     *
741
     * @return array The entity type with the passed entity type code
742
     */
743
    public function loadEntityTypeByEntityTypeCode($entityTypeCode)
744
    {
745
        return $this->getEntityTypeRepository()->findOneByEntityTypeCode($entityTypeCode);
746
    }
747
748
    /**
749
     * Return's the EAV attribute with the passed entity type ID and code.
750
     *
751
     * @param integer $entityTypeId  The entity type ID of the EAV attribute to return
752
     * @param string  $attributeCode The code of the EAV attribute to return
753
     *
754
     * @return array The EAV attribute
755
     */
756
    public function loadAttributeByEntityTypeIdAndAttributeCode($entityTypeId, $attributeCode)
757
    {
758
        return $this->getAttributeRepository()->findOneByEntityIdAndAttributeCode($entityTypeId, $attributeCode);
759
    }
760
761
    /**
762
     * Load's and return's the EAV attribute option with the passed entity type ID, code, store ID and value.
763
     *
764
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load the option for
765
     * @param string  $attributeCode The code of the EAV attribute option to load
766
     * @param integer $storeId       The store ID of the attribute option to load
767
     * @param string  $value         The value of the attribute option to load
768
     *
769
     * @return array The EAV attribute option
770
     */
771
    public function loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)
772
    {
773
        return $this->getAttributeOptionRepository()->findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value);
774
    }
775
776
    /**
777
     * Load's and return's the EAV attribute option with the passed entity type ID and code, store ID, swatch and type.
778
     *
779
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load the option for
780
     * @param string  $attributeCode The code of the EAV attribute option to load
781
     * @param integer $storeId       The store ID of the attribute option to load
782
     * @param string  $swatch        The swatch of the attribute option to load
783
     * @param string  $type          The swatch type of the attribute option to load
784
     *
785
     * @return array The EAV attribute option
786
     */
787
    public function loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndType($entityTypeId, $attributeCode, $storeId, $swatch, $type)
788
    {
789
        return $this->getAttributeOptionRepostory()->findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndType($entityTypeId, $attributeCode, $storeId, $swatch, $type);
0 ignored issues
show
Bug introduced by
The method getAttributeOptionRepostory() does not exist on TechDivision\Import\Attr...AttributeBunchProcessor. Did you maybe mean getAttributeOptionRepository()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
790
    }
791
792
    /**
793
     * Load's and return's the EAV attribute option value with the passed code, store ID and value.
794
     *
795
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load th option for
796
     * @param string  $attributeCode The code of the EAV attribute option to load
797
     * @param integer $storeId       The store ID of the attribute option to load
798
     * @param string  $value         The value of the attribute option to load
799
     *
800
     * @return array The EAV attribute option value
801
     */
802
    public function loadAttributeOptionValueByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value)
803
    {
804
        return $this->getEavAttributeOptionValueRepository()->findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value);
805
    }
806
807
    /**
808
     * Load's and return's the EAV attribute option swatch with the passed code, store ID, value and type.
809
     *
810
     * @param string  $entityTypeId  The entity type ID of the EAV attribute to load th option for
811
     * @param string  $attributeCode The code of the EAV attribute option swatch to load
812
     * @param integer $storeId       The store ID of the attribute option swatch to load
813
     * @param string  $value         The value of the attribute option swatch to load
814
     * @param string  $type          The type of the attribute option swatch to load
815
     *
816
     * @return array The EAV attribute option swatch
817
     */
818
    public function loadAttributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId, $attributeCode, $storeId, $value, $type)
819
    {
820
        return $this->getAttributeOptionSwatchRepository()->findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId, $attributeCode, $storeId, $value, $type);
821
    }
822
823
    /**
824
     * Returns the EAV attribute option of attribute with the passed ID with the highest sort order.
825
     *
826
     * @param integer $attributeId The ID of the attribute to return the EAV option with the highest sort order for
827
     *
828
     * @return array|null The EAV attribute option with the highest sort order
829
     */
830
    public function loadAttributeOptionByAttributeIdAndHighestSortOrder($attributeId)
831
    {
832
        return $this->getAttributeOptionRepository()->findOneByAttributeIdAndHighestSortOrder($attributeId);
833
    }
834
835
    /**
836
     * Persist's the passed EAV attribute data and return's the ID.
837
     *
838
     * @param array       $attribute The attribute data to persist
839
     * @param string|null $name      The name of the prepared statement that has to be executed
840
     *
841
     * @return string The ID of the persisted attribute
842
     */
843
    public function persistAttribute(array $attribute, $name = null)
844
    {
845
        return $this->getAttributeAction()->persist($attribute, $name);
846
    }
847
848
    /**
849
     * Persist the passed attribute label.
850
     *
851
     * @param array       $attributeLabel The attribute label to persist
852
     * @param string|null $name           The name of the prepared statement that has to be executed
853
     *
854
     * @return void
855
     */
856
    public function persistAttributeLabel(array $attributeLabel, $name = null)
857
    {
858
        $this->getAttributeLabelAction()->persist($attributeLabel, $name);
859
    }
860
861
    /**
862
     * Persist's the passed EAV attribute option data and return's the ID.
863
     *
864
     * @param array       $attributeOption The attribute option data to persist
865
     * @param string|null $name            The name of the prepared statement that has to be executed
866
     *
867
     * @return string The ID of the persisted attribute
868
     */
869
    public function persistAttributeOption(array $attributeOption, $name = null)
870
    {
871
        return $this->getAttributeOptionAction()->persist($attributeOption, $name);
872
    }
873
874
    /**
875
     * Persist's the passed EAV attribute option value data and return's the ID.
876
     *
877
     * @param array       $attributeOptionValue The attribute option value data to persist
878
     * @param string|null $name                 The name of the prepared statement that has to be executed
879
     *
880
     * @return void
881
     */
882
    public function persistAttributeOptionValue(array $attributeOptionValue, $name = null)
883
    {
884
        $this->getAttributeOptionValueAction()->persist($attributeOptionValue, $name);
885
    }
886
887
    /**
888
     * Persist the passed attribute option swatch.
889
     *
890
     * @param array       $attributeOptionSwatch The attribute option swatch to persist
891
     * @param string|null $name                  The name of the prepared statement that has to be executed
892
     *
893
     * @return void
894
     */
895
    public function persistAttributeOptionSwatch(array $attributeOptionSwatch, $name = null)
896
    {
897
        $this->getAttributeOptionSwatchAction()->persist($attributeOptionSwatch, $name);
898
    }
899
900
    /**
901
     * Persist's the passed EAV catalog attribute data and return's the ID.
902
     *
903
     * @param array       $catalogAttribute The catalog attribute data to persist
904
     * @param string|null $name             The name of the prepared statement that has to be executed
905
     *
906
     * @return void
907
     */
908
    public function persistCatalogAttribute(array $catalogAttribute, $name = null)
909
    {
910
        $this->getCatalogAttributeAction()->persist($catalogAttribute, $name);
911
    }
912
913
    /**
914
     * Persist's the passed EAV entity attribute data and return's the ID.
915
     *
916
     * @param array       $entityAttribute The entity attribute data to persist
917
     * @param string|null $name            The name of the prepared statement that has to be executed
918
     *
919
     * @return void
920
     */
921
    public function persistEntityAttribute(array $entityAttribute, $name = null)
922
    {
923
        $this->getEntityAttributeAction()->persist($entityAttribute, $name);
924
    }
925
926
    /**
927
     * Delete's the EAV attribute with the passed attributes.
928
     *
929
     * @param array       $row  The attributes of the EAV attribute to delete
930
     * @param string|null $name The name of the prepared statement that has to be executed
931
     *
932
     * @return void
933
     */
934
    public function deleteAttribute($row, $name = null)
935
    {
936
        $this->getAttributeAction()->delete($row, $name);
937
    }
938
}
939