Completed
Push — master ( f7ddb9...eb6557 )
by Tim
9s
created

getEavAttributeGroupsByAttributeSetId()   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 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Services\ImportProcessor
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Services;
22
23
use TechDivision\Import\Utils\RegistryKeys;
24
use TechDivision\Import\Utils\MemberNames;
25
use TechDivision\Import\Assembler\CategoryAssembler;
26
use TechDivision\Import\Repositories\CategoryRepository;
27
use TechDivision\Import\Repositories\CategoryVarcharRepository;
28
use TechDivision\Import\Repositories\EavAttributeRepository;
29
use TechDivision\Import\Repositories\EavAttributeSetRepository;
30
use TechDivision\Import\Repositories\EavAttributeGroupRepository;
31
use TechDivision\Import\Repositories\EavEntityTypeRepository;
32
use TechDivision\Import\Repositories\StoreRepository;
33
use TechDivision\Import\Repositories\StoreWebsiteRepository;
34
use TechDivision\Import\Repositories\TaxClassRepository;
35
use TechDivision\Import\Repositories\LinkTypeRepository;
36
use TechDivision\Import\Repositories\LinkAttributeRepository;
37
use TechDivision\Import\Repositories\CoreConfigDataRepository;
38
39
/**
40
 * Processor implementation to load global data.
41
 *
42
 * @author    Tim Wagner <[email protected]>
43
 * @copyright 2016 TechDivision GmbH <[email protected]>
44
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
45
 * @link      https://github.com/techdivision/import
46
 * @link      http://www.techdivision.com
47
 */
48
class ImportProcessor implements ImportProcessorInterface
49
{
50
51
    /**
52
     * A PDO connection initialized with the values from the Doctrine EntityManager.
53
     *
54
     * @var \PDO
55
     */
56
    protected $connection;
57
58
    /**
59
     * The category assembler instance.
60
     *
61
     * @var \TechDivision\Import\Assembler\CategoryAssembler
62
     */
63
    protected $categoryAssembler;
64
65
    /**
66
     * The repository to access categories.
67
     *
68
     * @var \TechDivision\Import\Repositories\CategoryRepository
69
     */
70
    protected $categoryRepository;
71
72
    /**
73
     * The repository to access category varchar values.
74
     *
75
     * @var \TechDivision\Import\Repositories\CategoryVarcharRepository
76
     */
77
    protected $categoryVarcharRepository;
78
79
    /**
80
     * The repository to access EAV attributes.
81
     *
82
     * @var \TechDivision\Import\Repositories\EavAttributeRepository
83
     */
84
    protected $eavAttributeRepository;
85
86
    /**
87
     * The repository to access EAV attribute sets.
88
     *
89
     * @var \TechDivision\Import\Repositories\EavAttributeSetRepository
90
     */
91
    protected $eavAttributeSetRepository;
92
93
    /**
94
     * The repository to access EAV attribute groups.
95
     *
96
     * @var \TechDivision\Import\Repositories\EavAttributeGroupRepository
97
     */
98
    protected $eavAttributeGroupRepository;
99
100
    /**
101
     * The repository to access EAV entity types.
102
     *
103
     * @var \TechDivision\Import\Repositories\EavEntityTypeRepository
104
     */
105
    protected $eavEntityTypeRepository;
106
107
    /**
108
     * The repository to access stores.
109
     *
110
     * @var \TechDivision\Import\Repositories\StoreRepository
111
     */
112
    protected $storeRepository;
113
114
    /**
115
     * The repository to access store websites.
116
     *
117
     * @var \TechDivision\Import\Repositories\StoreWebsiteRepository
118
     */
119
    protected $storeWebsiteRepository;
120
121
    /**
122
     * The repository to access tax classes.
123
     *
124
     * @var \TechDivision\Import\Repositories\TaxClassRepository
125
     */
126
    protected $taxClassRepository;
127
128
    /**
129
     * The repository to access link types.
130
     *
131
     * @var \TechDivision\Import\Repositories\LinkTypeRepository
132
     */
133
    protected $linkTypeRepository;
134
135
    /**
136
     * The repository to access link attributes.
137
     *
138
     * @var \TechDivision\Import\Repositories\LinkAttributeRepository
139
     */
140
    protected $linkAttributeRepository;
141
142
    /**
143
     * The repository to access the configuration.
144
     *
145
     * @var \TechDivision\Import\Repositories\CoreConfigDataRepository
146
     */
147
    protected $coreConfigDataRepository;
148
149
    /**
150
     * Initialize the processor with the necessary assembler and repository instances.
151
     *
152
     * @param \PDO                                                          $connection                  The PDO connection to use
153
     * @param \TechDivision\Import\Assembler\CategoryAssembler              $categoryAssembler           The category assembler instance
154
     * @param \TechDivision\Import\Repositories\CategoryRepository          $categoryRepository          The repository to access categories
155
     * @param \TechDivision\Import\Repositories\CategoryVarcharRepository   $categoryVarcharRepository   The repository to access category varchar values
156
     * @param \TechDivision\Import\Repositories\EavAttributeRepository      $eavAttributeRepository      The repository to access EAV attributes
157
     * @param \TechDivision\Import\Repositories\EavAttributeSetRepository   $eavAttributeSetRepository   The repository to access EAV attribute sets
158
     * @param \TechDivision\Import\Repositories\EavAttributeGroupRepository $eavAttributeGroupRepository The repository to access EAV attribute groups
159
     * @param \TechDivision\Import\Repositories\EavEntityTypeRepository     $eavEntityTypeRepository     The repository to access EAV entity types
160
     * @param \TechDivision\Import\Repositories\StoreRepository             $storeRepository             The repository to access stores
161
     * @param \TechDivision\Import\Repositories\StoreWebsiteRepository      $storeWebsiteRepository      The repository to access store websites
162
     * @param \TechDivision\Import\Repositories\TaxClassRepository          $taxClassRepository          The repository to access tax classes
163
     * @param \TechDivision\Import\Repositories\LinkTypeRepository          $linkTypeRepository          The repository to access link types
164
     * @param \TechDivision\Import\Repositories\LinkAttributeRepository     $linkAttributeRepository     The repository to access link attributes
165
     * @param \TechDivision\Import\Repositories\CoreConfigDataRepository    $coreConfigDataRepository    The repository to access the configuration
166
     */
167
    public function __construct(
168
        \PDO $connection,
169
        CategoryAssembler $categoryAssembler,
170
        CategoryRepository $categoryRepository,
171
        CategoryVarcharRepository $categoryVarcharRepository,
172
        EavAttributeRepository $eavAttributeRepository,
173
        EavAttributeSetRepository $eavAttributeSetRepository,
174
        EavAttributeGroupRepository $eavAttributeGroupRepository,
175
        EavEntityTypeRepository $eavEntityTypeRepository,
176
        StoreRepository $storeRepository,
177
        StoreWebsiteRepository $storeWebsiteRepository,
178
        TaxClassRepository $taxClassRepository,
179
        LinkTypeRepository $linkTypeRepository,
180
        LinkAttributeRepository $linkAttributeRepository,
181
        CoreConfigDataRepository $coreConfigDataRepository
182
    ) {
183
        $this->setConnection($connection);
184
        $this->setCategoryAssembler($categoryAssembler);
185
        $this->setCategoryRepository($categoryRepository);
186
        $this->setCategoryVarcharRepository($categoryVarcharRepository);
187
        $this->setEavAttributeRepository($eavAttributeRepository);
188
        $this->setEavAttributeSetRepository($eavAttributeSetRepository);
189
        $this->setEavAttributeGroupRepository($eavAttributeGroupRepository);
190
        $this->setEavEntityTypeRepository($eavEntityTypeRepository);
191
        $this->setStoreRepository($storeRepository);
192
        $this->setStoreWebsiteRepository($storeWebsiteRepository);
193
        $this->setTaxClassRepository($taxClassRepository);
194
        $this->setLinkTypeRepository($linkTypeRepository);
195
        $this->setLinkAttributeRepository($linkAttributeRepository);
0 ignored issues
show
Documentation introduced by
$linkAttributeRepository is of type object<TechDivision\Impo...inkAttributeRepository>, but the function expects a object<TechDivision\Impo...ies\LinkTypeRepository>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
196
        $this->setCoreConfigDataRepository($coreConfigDataRepository);
197
    }
198
199
    /**
200
     * Set's the passed connection.
201
     *
202
     * @param \PDO $connection The connection to set
203
     *
204
     * @return void
205
     */
206
    public function setConnection(\PDO $connection)
207
    {
208
        $this->connection = $connection;
209
    }
210
211
    /**
212
     * Return's the connection.
213
     *
214
     * @return \PDO The connection instance
215
     */
216
    public function getConnection()
217
    {
218
        return $this->connection;
219
    }
220
221
    /**
222
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
223
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
224
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
225
     * to autocommit mode.
226
     *
227
     * @return boolean Returns TRUE on success or FALSE on failure
228
     * @link http://php.net/manual/en/pdo.begintransaction.php
229
     */
230
    public function beginTransaction()
231
    {
232
        return $this->connection->beginTransaction();
233
    }
234
235
    /**
236
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
237
     * ProductProcessor::beginTransaction() starts a new transaction.
238
     *
239
     * @return boolean Returns TRUE on success or FALSE on failure
240
     * @link http://php.net/manual/en/pdo.commit.php
241
     */
242
    public function commit()
243
    {
244
        return $this->connection->commit();
245
    }
246
247
    /**
248
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
249
     *
250
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
251
     * rolled back the transaction.
252
     *
253
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
254
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
255
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
256
     *
257
     * @return boolean Returns TRUE on success or FALSE on failure
258
     * @link http://php.net/manual/en/pdo.rollback.php
259
     */
260
    public function rollBack()
261
    {
262
        return $this->connection->rollBack();
263
    }
264
265
    /**
266
     * Set's the category assembler.
267
     *
268
     * @param \TechDivision\Import\Assembler\CategoryAssembler $categoryAssembler The category assembler
269
     *
270
     * @return void
271
     */
272
    public function setCategoryAssembler($categoryAssembler)
273
    {
274
        $this->categoryAssembler = $categoryAssembler;
275
    }
276
277
    /**
278
     * Return's the category assembler.
279
     *
280
     * @return \TechDivision\Import\Assembler\CategoryAssembler The category assembler instance
281
     */
282
    public function getCategoryAssembler()
283
    {
284
        return $this->categoryAssembler;
285
    }
286
287
    /**
288
     * Set's the repository to access categories.
289
     *
290
     * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories
291
     *
292
     * @return void
293
     */
294
    public function setCategoryRepository($categoryRepository)
295
    {
296
        $this->categoryRepository = $categoryRepository;
297
    }
298
299
    /**
300
     * Return's the repository to access categories.
301
     *
302
     * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance
303
     */
304
    public function getCategoryRepository()
305
    {
306
        return $this->categoryRepository;
307
    }
308
309
    /**
310
     * Return's the repository to access category varchar values.
311
     *
312
     * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance
313
     *
314
     * @return void
315
     */
316
    public function setCategoryVarcharRepository($categoryVarcharRepository)
317
    {
318
        $this->categoryVarcharRepository = $categoryVarcharRepository;
319
    }
320
321
    /**
322
     * Return's the repository to access category varchar values.
323
     *
324
     * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance
325
     */
326
    public function getCategoryVarcharRepository()
327
    {
328
        return $this->categoryVarcharRepository;
329
    }
330
331
    /**
332
     * Set's the repository to access EAV attributes.
333
     *
334
     * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes
335
     *
336
     * @return void
337
     */
338
    public function setEavAttributeRepository($eavAttributeRepository)
339
    {
340
        $this->eavAttributeRepository = $eavAttributeRepository;
341
    }
342
343
    /**
344
     * Return's the repository to access EAV attributes.
345
     *
346
     * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance
347
     */
348
    public function getEavAttributeRepository()
349
    {
350
        return $this->eavAttributeRepository;
351
    }
352
353
    /**
354
     * Set's the repository to access EAV attribute sets.
355
     *
356
     * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets
357
     *
358
     * @return void
359
     */
360
    public function setEavAttributeSetRepository($eavAttributeSetRepository)
361
    {
362
        $this->eavAttributeSetRepository = $eavAttributeSetRepository;
363
    }
364
365
    /**
366
     * Return's the repository to access EAV attribute sets.
367
     *
368
     * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance
369
     */
370
    public function getEavAttributeSetRepository()
371
    {
372
        return $this->eavAttributeSetRepository;
373
    }
374
375
    /**
376
     * Set's the repository to access EAV attribute groups.
377
     *
378
     * @param \TechDivision\Import\Repositories\EavAttributeGroupRepository $eavAttributeGroupRepository The repository the access EAV attribute groups
379
     *
380
     * @return void
381
     */
382
    public function setEavAttributeGroupRepository($eavAttributeGroupRepository)
383
    {
384
        $this->eavAttributeGroupRepository = $eavAttributeGroupRepository;
385
    }
386
387
    /**
388
     * Return's the repository to access EAV attribute groups.
389
     *
390
     * @return \TechDivision\Import\Repositories\EavAttributeGroupRepository The repository instance
391
     */
392
    public function getEavAttributeGroupRepository()
393
    {
394
        return $this->eavAttributeGroupRepository;
395
    }
396
397
    /**
398
     * Return's the repository to access EAV entity types.
399
     *
400
     * @return \TechDivision\Import\Repositories\EavEntityTypeRepository The repository instance
401
     */
402
    public function getEavEntityTypeRepository()
403
    {
404
        return $this->eavEntityTypeRepository;
405
    }
406
407
    /**
408
     * Set's the repository to access EAV entity types.
409
     *
410
     * @param \TechDivision\Import\Repositories\EavEntityTypeRepository $eavEntityTypeRepository The repository the access EAV entity types
411
     *
412
     * @return void
413
     */
414
    public function setEavEntityTypeRepository($eavEntityTypeRepository)
415
    {
416
        $this->eavEntityTypeRepository = $eavEntityTypeRepository;
417
    }
418
419
    /**
420
     * Set's the repository to access stores.
421
     *
422
     * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores
423
     *
424
     * @return void
425
     */
426
    public function setStoreRepository($storeRepository)
427
    {
428
        $this->storeRepository = $storeRepository;
429
    }
430
431
    /**
432
     * Return's the repository to access stores.
433
     *
434
     * @return \TechDivision\Import\Repositories\StoreRepository The repository instance
435
     */
436
    public function getStoreRepository()
437
    {
438
        return $this->storeRepository;
439
    }
440
441
    /**
442
     * Set's the repository to access store websites.
443
     *
444
     * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites
445
     *
446
     * @return void
447
     */
448
    public function setStoreWebsiteRepository($storeWebsiteRepository)
449
    {
450
        $this->storeWebsiteRepository = $storeWebsiteRepository;
451
    }
452
453
    /**
454
     * Return's the repository to access store websites.
455
     *
456
     * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance
457
     */
458
    public function getStoreWebsiteRepository()
459
    {
460
        return $this->storeWebsiteRepository;
461
    }
462
463
    /**
464
     * Set's the repository to access tax classes.
465
     *
466
     * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores
467
     *
468
     * @return void
469
     */
470
    public function setTaxClassRepository($taxClassRepository)
471
    {
472
        $this->taxClassRepository = $taxClassRepository;
473
    }
474
475
    /**
476
     * Return's the repository to access tax classes.
477
     *
478
     * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance
479
     */
480
    public function getTaxClassRepository()
481
    {
482
        return $this->taxClassRepository;
483
    }
484
485
    /**
486
     * Set's the repository to access link types.
487
     *
488
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types
489
     *
490
     * @return void
491
     */
492
    public function setLinkTypeRepository($linkTypeRepository)
493
    {
494
        $this->linkTypeRepository = $linkTypeRepository;
495
    }
496
497
    /**
498
     * Return's the repository to access link types.
499
     *
500
     * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance
501
     */
502
    public function getLinkTypeRepository()
503
    {
504
        return $this->linkTypeRepository;
505
    }
506
507
    /**
508
     * Set's the repository to access link attributes.
509
     *
510
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes
511
     *
512
     * @return void
513
     */
514
    public function setLinkAttributeRepository($linkAttributeRepository)
515
    {
516
        $this->linkAttributeRepository = $linkAttributeRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $linkAttributeRepository of type object<TechDivision\Impo...ies\LinkTypeRepository> is incompatible with the declared type object<TechDivision\Impo...inkAttributeRepository> of property $linkAttributeRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
517
    }
518
519
    /**
520
     * Return's the repository to access link attributes.
521
     *
522
     * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance
523
     */
524
    public function getLinkAttributeRepository()
525
    {
526
        return $this->linkAttributeRepository;
527
    }
528
529
    /**
530
     * Set's the repository to access the Magento 2 configuration.
531
     *
532
     * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration
533
     *
534
     * @return void
535
     */
536
    public function setCoreConfigDataRepository($coreConfigDataRepository)
537
    {
538
        $this->coreConfigDataRepository = $coreConfigDataRepository;
539
    }
540
541
    /**
542
     * Return's the repository to access the Magento 2 configuration.
543
     *
544
     * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance
545
     */
546
    public function getCoreConfigDataRepository()
547
    {
548
        return $this->coreConfigDataRepository;
549
    }
550
551
    /**
552
     * Return's the EAV attribute set with the passed ID.
553
     *
554
     * @param integer $id The ID of the EAV attribute set to load
555
     *
556
     * @return array The EAV attribute set
557
     */
558
    public function getEavAttributeSet($id)
559
    {
560
        return $this->getEavAttributeSetRepository()->load($id);
561
    }
562
563
    /**
564
     * Return's the attribute sets for the passed entity type ID.
565
     *
566
     * @param mixed $entityTypeId The entity type ID to return the attribute sets for
567
     *
568
     * @return array|boolean The attribute sets for the passed entity type ID
569
     */
570
    public function getEavAttributeSetsByEntityTypeId($entityTypeId)
571
    {
572
        return $this->getEavAttributeSetRepository()->findAllByEntityTypeId($entityTypeId);
573
    }
574
575
    /**
576
     * Return's the attribute groups for the passed attribute set ID, whereas the array
577
     * is prepared with the attribute group names as keys.
578
     *
579
     * @param mixed $attributeSetId The EAV attribute set ID to return the attribute groups for
580
     *
581
     * @return array|boolean The EAV attribute groups for the passed attribute ID
582
     */
583
    public function getEavAttributeGroupsByAttributeSetId($attributeSetId)
584
    {
585
        return $this->getEavAttributeGroupRepository()->findAllByAttributeSetId($attributeSetId);
586
    }
587
588
    /**
589
     * Return's an array with the EAV attributes for the passed entity type ID and attribute set name.
590
     *
591
     * @param integer $entityTypeId     The entity type ID of the EAV attributes to return
592
     * @param string  $attributeSetName The attribute set name of the EAV attributes to return
593
     *
594
     * @return array The
595
     */
596
    public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
597
    {
598
        return $this->getEavAttributeRepository()->findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName);
599
    }
600
601
    /**
602
     * Return's an array with the available EAV attributes for the passed option value and store ID.
603
     *
604
     * @param string $optionValue The option value of the EAV attributes
605
     * @param string $storeId     The store ID of the EAV attribues
606
     *
607
     * @return array The array with all available EAV attributes
608
     */
609
    public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId)
610
    {
611
        return $this->getEavAttributeRepository()->findAllByOptionValueAndStoreId($optionValue, $storeId);
612
    }
613
614
    /**
615
     * Return's the first EAV attribute for the passed option value and store ID.
616
     *
617
     * @param string $optionValue The option value of the EAV attributes
618
     * @param string $storeId     The store ID of the EAV attribues
619
     *
620
     * @return array The array with the EAV attribute
621
     */
622
    public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId)
623
    {
624
        return $this->getEavAttributeRepository()->findOneByOptionValueAndStoreId($optionValue, $storeId);
625
    }
626
627
    /**
628
     * Return's an array with the available EAV attributes for the passed is user defined flag.
629
     *
630
     * @param integer $isUserDefined The flag itself
631
     *
632
     * @return array The array with the EAV attributes matching the passed flag
633
     */
634
    public function getEavAttributesByIsUserDefined($isUserDefined = 1)
635
    {
636
        return $this->getEavAttributeRepository()->findAllByIsUserDefined($isUserDefined);
637
    }
638
639
    /**
640
     * Return's an array with the available EAV attributes for the passed is entity type and
641
     * user defined flag.
642
     *
643
     * @param integer $entityTypeId  The entity type ID of the EAV attributes to return
644
     * @param integer $isUserDefined The flag itself
645
     *
646
     * @return array The array with the EAV attributes matching the passed entity type and user defined flag
647
     */
648
    public function getEavAttributesByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined = 1)
649
    {
650
        return $this->getEavAttributeRepository()->findAllByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined);
651
    }
652
653
    /**
654
     * Return's an array with all available EAV entity types with the entity type code as key.
655
     *
656
     * @return array The available link types
657
     */
658
    public function getEavEntityTypes()
659
    {
660
        return $this->getEavEntityTypeRepository()->findAll();
661
    }
662
663
    /**
664
     * Return's an array with the available stores.
665
     *
666
     * @return array The array with the available stores
667
     */
668
    public function getStores()
669
    {
670
        return $this->getStoreRepository()->findAll();
671
    }
672
673
    /**
674
     * Return's the default store.
675
     *
676
     * @return array The default store
677
     */
678
    public function getDefaultStore()
679
    {
680
        return $this->getStoreRepository()->findOneByDefault();
681
    }
682
683
    /**
684
     * Return's an array with the available store websites.
685
     *
686
     * @return array The array with the available store websites
687
     */
688
    public function getStoreWebsites()
689
    {
690
        return $this->getStoreWebsiteRepository()->findAll();
691
    }
692
693
    /**
694
     * Return's an array with the available tax classes.
695
     *
696
     * @return array The array with the available tax classes
697
     */
698
    public function getTaxClasses()
699
    {
700
        return $this->getTaxClassRepository()->findAll();
701
    }
702
703
    /**
704
     * Return's an array with all available categories.
705
     *
706
     * @return array The available categories
707
     */
708
    public function getCategories()
709
    {
710
        return $this->getCategoryRepository()->findAll();
711
    }
712
713
    /**
714
     * Return's an array with the root categories with the store code as key.
715
     *
716
     * @return array The root categories
717
     */
718
    public function getRootCategories()
719
    {
720
        return $this->getCategoryRepository()->findAllRootCategories();
721
    }
722
723
    /**
724
     * Returns the category varchar values for the categories with
725
     * the passed with the passed entity IDs.
726
     *
727
     * @param array $entityIds The array with the category IDs
728
     *
729
     * @return mixed The category varchar values
730
     */
731
    public function getCategoryVarcharsByEntityIds(array $entityIds)
732
    {
733
        return $this->getCategoryVarcharRepository()->findAllByEntityIds($entityIds);
734
    }
735
736
    /**
737
     * Return's an array with all available link types.
738
     *
739
     * @return array The available link types
740
     */
741
    public function getLinkTypes()
742
    {
743
        return $this->getLinkTypeRepository()->findAll();
744
    }
745
746
    /**
747
     * Return's an array with all available link attributes.
748
     *
749
     * @return array The available link attributes
750
     */
751
    public function getLinkAttributes()
752
    {
753
        return $this->getLinkAttributeRepository()->findAll();
754
    }
755
756
    /**
757
     * Return's an array with the Magento 2 configuration.
758
     *
759
     * @return array The Magento 2 configuration
760
     */
761
    public function getCoreConfigData()
762
    {
763
        return $this->getCoreConfigDataRepository()->findAll();
764
    }
765
766
    /**
767
     * Returns the array with the global data necessary for the
768
     * import process.
769
     *
770
     * @return array The array with the global data
771
     */
772
    public function getGlobalData()
773
    {
774
775
        // initialize the array for the global data
776
        $globalData = array();
777
778
        // initialize the global data
779
        $globalData[RegistryKeys::STORES] = $this->getStores();
780
        $globalData[RegistryKeys::LINK_TYPES] = $this->getLinkTypes();
781
        $globalData[RegistryKeys::TAX_CLASSES] = $this->getTaxClasses();
782
        $globalData[RegistryKeys::DEFAULT_STORE] = $this->getDefaultStore();
783
        $globalData[RegistryKeys::STORE_WEBSITES] = $this->getStoreWebsites();
784
        $globalData[RegistryKeys::LINK_ATTRIBUTES] = $this->getLinkAttributes();
785
        $globalData[RegistryKeys::ROOT_CATEGORIES] = $this->getRootCategories();
786
        $globalData[RegistryKeys::CORE_CONFIG_DATA] = $this->getCoreConfigData();
787
        $globalData[RegistryKeys::ENTITY_TYPES] = $eavEntityTypes = $this->getEavEntityTypes();
788
789
        // prepare the attribute sets
790
        $eavAttributes = array();
791
        $eavAttributeSets = array();
792
        $eavAttributeGroups = array();
793
        foreach ($eavEntityTypes as $eavEntityTypeCode => $eavEntityType) {
794
            // load the attribute sets for the entity type
795
            $attributeSets = $this->getEavAttributeSetsByEntityTypeId($entityTypeId = $eavEntityType[MemberNames::ENTITY_TYPE_ID]);
796
            // append the attribute sets to the array
797
            $eavAttributeSets[$eavEntityTypeCode] = $attributeSets;
798
799
            // iterate over the attribute sets and initialize the attributes
800
            foreach ($attributeSets as $attributeSet) {
0 ignored issues
show
Bug introduced by
The expression $attributeSets of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
801
                // load the attribute set name
802
                $eavAttributeSetName = $attributeSet[MemberNames::ATTRIBUTE_SET_NAME];
803
804
                // load the attributes for the attribute set
805
                $eavAttributes[$eavEntityTypeCode][$eavAttributeSetName] = $this->getEavAttributesByEntityTypeIdAndAttributeSetName(
806
                    $entityTypeId,
807
                    $eavAttributeSetName
808
                );
809
810
                // load the attribute group for the attribute set
811
                $eavAttributeGroups[$eavEntityTypeCode][$eavAttributeSetName] = $this->getEavAttributeGroupsByAttributeSetId(
812
                    $attributeSet[MemberNames::ATTRIBUTE_SET_ID]
813
                );
814
            }
815
        }
816
817
        // prepare the user defined attributes
818
        $eavUserDefinedAttributes = array();
819
        foreach ($eavEntityTypes as $eavEntityTypeCode => $eavEntityType) {
820
            // load the user defined attributes for the entity type
821
            $eavUserDefinedAttributes[$eavEntityTypeCode] = $this->getEavAttributesByEntityTypeIdAndIsUserDefined(
822
                $eavEntityType[MemberNames::ENTITY_TYPE_ID]
823
            );
824
        }
825
826
        // initialize the arrays with the EAV attributes, EAV user defined attributes and attribute sets/groups
827
        $globalData[RegistryKeys::EAV_ATTRIBUTES] = $eavAttributes;
828
        $globalData[RegistryKeys::ATTRIBUTE_SETS] = $eavAttributeSets;
829
        $globalData[RegistryKeys::ATTRIBUTE_GROUPS] = $eavAttributeGroups;
830
        $globalData[RegistryKeys::EAV_USER_DEFINED_ATTRIBUTES] = $eavUserDefinedAttributes;
831
832
        // initialize the array with the avaliable categories
833
        $globalData[RegistryKeys::CATEGORIES] = $this->categoryAssembler->getCategoriesWithResolvedPath();
834
835
        // return the array
836
        return $globalData;
837
    }
838
}
839