Completed
Pull Request — master (#53)
by Tim
10:36
created

ImportProcessor::getStoreRepository()   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
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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
26
/**
27
 * Processor implementation to load global data.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class ImportProcessor implements ImportProcessorInterface
36
{
37
38
    /**
39
     * A PDO connection initialized with the values from the Doctrine EntityManager.
40
     *
41
     * @var \PDO
42
     */
43
    protected $connection;
44
45
    /**
46
     * The category assembler instance.
47
     *
48
     * @var \TechDivision\Import\Assembler\CategoryAssembler
49
     */
50
    protected $categoryAssembler;
51
52
    /**
53
     * The repository to access categories.
54
     *
55
     * @var \TechDivision\Import\Repositories\CategoryRepository
56
     */
57
    protected $categoryRepository;
58
59
    /**
60
     * The repository to access category varchar values.
61
     *
62
     * @var \TechDivision\Import\Repositories\CategoryVarcharRepository
63
     */
64
    protected $categoryVarcharRepository;
65
66
    /**
67
     * The repository to access EAV attributes.
68
     *
69
     * @var \TechDivision\Import\Repositories\EavAttributeRepository
70
     */
71
    protected $eavAttributeRepository;
72
73
    /**
74
     * The repository to access EAV attribute set.
75
     *
76
     * @var \TechDivision\Import\Repositories\EavAttributeSetRepository
77
     */
78
    protected $eavAttributeSetRepository;
79
80
    /**
81
     * The repository to access EAV entity types.
82
     *
83
     * @var \TechDivision\Import\Repositories\EavEntityTypeRepository
84
     */
85
    protected $eavEntityTypeRepository;
86
87
    /**
88
     * The repository to access stores.
89
     *
90
     * @var \TechDivision\Import\Repositories\StoreRepository
91
     */
92
    protected $storeRepository;
93
94
    /**
95
     * The repository to access store websites.
96
     *
97
     * @var \TechDivision\Import\Repositories\StoreWebsiteRepository
98
     */
99
    protected $storeWebsiteRepository;
100
101
    /**
102
     * The repository to access tax classes.
103
     *
104
     * @var \TechDivision\Import\Repositories\TaxClassRepository
105
     */
106
    protected $taxClassRepository;
107
108
    /**
109
     * The repository to access link types.
110
     *
111
     * @var \TechDivision\Import\Repositories\LinkTypeRepository
112
     */
113
    protected $linkTypeRepository;
114
115
    /**
116
     * The repository to access link attributes.
117
     *
118
     * @var \TechDivision\Import\Repositories\LinkAttributeRepository
119
     */
120
    protected $linkAttributeRepository;
121
122
    /**
123
     * The repository to access the configuration.
124
     *
125
     * @var \TechDivision\Import\Repositories\CoreConfigDataRepository
126
     */
127
    protected $coreConfigDataRepository;
128
129
    /**
130
     * Initialize the processor with the necessary assembler and repository instances.
131
     *
132
     * @param \PDO                                                        $connection                The PDO connection to use
133
     * @param \TechDivision\Import\Assembler\CategoryAssembler            $categoryAssembler         The category assembler instance
134
     * @param \TechDivision\Import\Repositories\CategoryRepository        $categoryRepository        The repository to access categories
135
     * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository to access category varchar values
136
     * @param \TechDivision\Import\Repositories\EavAttributeRepository    $eavAttributeRepository    The repository to access EAV attributes
137
     * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository to access EAV attribute set
138
     * @param \TechDivision\Import\Repositories\EavEntityTypeRepository   $eavEntityTypeRepository   The repository to access EAV entity types
139
     * @param \TechDivision\Import\Repositories\StoreRepository           $storeRepository           The repository to access stores
140
     * @param \TechDivision\Import\Repositories\StoreWebsiteRepository    $storeWebsiteRepository    The repository to access store websites
141
     * @param \TechDivision\Import\Repositories\TaxClassRepository        $taxClassRepository        The repository to access tax classes
142
     * @param \TechDivision\Import\Repositories\LinkTypeRepository        $linkTypeRepository        The repository to access link types
143
     * @param \TechDivision\Import\Repositories\LinkAttributeRepository   $linkAttributeRepository   The repository to access link attributes
144
     * @param \TechDivision\Import\Repositories\CoreConfigDataRepository  $coreConfigDataRepository  The repository to access the configuration
145
     */
146
    public function __construct(
147
        \PDO $connection,
148
        CategoryAssembler $categoryAssembler,
149
        CategoryRepository $categoryRepository,
150
        CategoryVarcharRepository $categoryVarcharRepository,
151
        EavAttributeRepository $eavAttributeRepository,
152
        EavAttributeSetRepository $eavAttributeSetRepository,
153
        EavEntityTypeRepository $eavEntityTypeRepository,
154
        StoreRepository $storeRepository,
155
        StoreWebsiteRepository $storeWebsiteRepository,
156
        TaxClassRepository $taxClassRepository,
157
        LinkTypeRepository $linkTypeRepository,
158
        LinkAttributeRepository $linkAttributeRepository,
159
        CoreConfigDataRepository $coreConfigDataRepository
160
    ) {
161
        $this->setConnection($connection);
162
        $this->setCategoryAssembler($categoryAssembler);
163
        $this->setCategoryRepository($categoryRepository);
164
        $this->setCategoryVarcharRepository($categoryVarcharRepository);
165
        $this->setEavAttributeRepository($eavAttributeRepository);
166
        $this->setEavAttributeSetRepository($eavAttributeSetRepository);
167
        $this->setEavEntityTypeRepository($eavEntityTypeRepository);
168
        $this->setStoreRepository($storeRepository);
169
        $this->setStoreWebsiteRepository($storeWebsiteRepository);
170
        $this->setTaxClassRepository($taxClassRepository);
171
        $this->setLinkTypeRepository($linkTypeRepository);
172
        $this->setLinkAttributeRepository($linkAttributeRepository);
173
        $this->setCoreConfigDataRepository($coreConfigDataRepository);
174
    }
175
176
    /**
177
     * Set's the passed connection.
178
     *
179
     * @param \PDO $connection The connection to set
180
     *
181
     * @return void
182
     */
183
    public function setConnection(\PDO $connection)
184
    {
185
        $this->connection = $connection;
186
    }
187
188
    /**
189
     * Return's the connection.
190
     *
191
     * @return \PDO The connection instance
192
     */
193
    public function getConnection()
194
    {
195
        return $this->connection;
196
    }
197
198
    /**
199
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
200
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
201
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
202
     * to autocommit mode.
203
     *
204
     * @return boolean Returns TRUE on success or FALSE on failure
205
     * @link http://php.net/manual/en/pdo.begintransaction.php
206
     */
207
    public function beginTransaction()
208
    {
209
        return $this->connection->beginTransaction();
210
    }
211
212
    /**
213
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
214
     * ProductProcessor::beginTransaction() starts a new transaction.
215
     *
216
     * @return boolean Returns TRUE on success or FALSE on failure
217
     * @link http://php.net/manual/en/pdo.commit.php
218
     */
219
    public function commit()
220
    {
221
        return $this->connection->commit();
222
    }
223
224
    /**
225
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
226
     *
227
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
228
     * rolled back the transaction.
229
     *
230
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
231
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
232
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
233
     *
234
     * @return boolean Returns TRUE on success or FALSE on failure
235
     * @link http://php.net/manual/en/pdo.rollback.php
236
     */
237
    public function rollBack()
238
    {
239
        return $this->connection->rollBack();
240
    }
241
242
    /**
243
     * Set's the category assembler.
244
     *
245
     * @param \TechDivision\Import\Assembler\CategoryAssembler $categoryAssembler The category assembler
246
     *
247
     * @return void
248
     */
249
    public function setCategoryAssembler($categoryAssembler)
250
    {
251
        $this->categoryAssembler = $categoryAssembler;
252
    }
253
254
    /**
255
     * Return's the category assembler.
256
     *
257
     * @return \TechDivision\Import\Assembler\CategoryAssembler The category assembler instance
258
     */
259
    public function getCategoryAssembler()
260
    {
261
        return $this->categoryAssembler;
262
    }
263
264
    /**
265
     * Set's the repository to access categories.
266
     *
267
     * @param \TechDivision\Import\Repositories\CategoryRepository $categoryRepository The repository to access categories
268
     *
269
     * @return void
270
     */
271
    public function setCategoryRepository($categoryRepository)
272
    {
273
        $this->categoryRepository = $categoryRepository;
274
    }
275
276
    /**
277
     * Return's the repository to access categories.
278
     *
279
     * @return \TechDivision\Import\Repositories\CategoryRepository The repository instance
280
     */
281
    public function getCategoryRepository()
282
    {
283
        return $this->categoryRepository;
284
    }
285
286
    /**
287
     * Return's the repository to access category varchar values.
288
     *
289
     * @param \TechDivision\Import\Repositories\CategoryVarcharRepository $categoryVarcharRepository The repository instance
290
     *
291
     * @return void
292
     */
293
    public function setCategoryVarcharRepository($categoryVarcharRepository)
294
    {
295
        $this->categoryVarcharRepository = $categoryVarcharRepository;
296
    }
297
298
    /**
299
     * Return's the repository to access category varchar values.
300
     *
301
     * @return \TechDivision\Import\Repositories\CategoryVarcharRepository The repository instance
302
     */
303
    public function getCategoryVarcharRepository()
304
    {
305
        return $this->categoryVarcharRepository;
306
    }
307
308
    /**
309
     * Set's the repository to access EAV attributes.
310
     *
311
     * @param \TechDivision\Import\Repositories\EavAttributeRepository $eavAttributeRepository The repository to access EAV attributes
312
     *
313
     * @return void
314
     */
315
    public function setEavAttributeRepository($eavAttributeRepository)
316
    {
317
        $this->eavAttributeRepository = $eavAttributeRepository;
318
    }
319
320
    /**
321
     * Return's the repository to access EAV attributes.
322
     *
323
     * @return \TechDivision\Import\Repositories\EavAttributeRepository The repository instance
324
     */
325
    public function getEavAttributeRepository()
326
    {
327
        return $this->eavAttributeRepository;
328
    }
329
330
    /**
331
     * Set's the repository to access EAV attribute sets.
332
     *
333
     * @param \TechDivision\Import\Repositories\EavAttributeSetRepository $eavAttributeSetRepository The repository the access EAV attribute sets
334
     *
335
     * @return void
336
     */
337
    public function setEavAttributeSetRepository($eavAttributeSetRepository)
338
    {
339
        $this->eavAttributeSetRepository = $eavAttributeSetRepository;
340
    }
341
342
    /**
343
     * Return's the repository to access EAV attribute sets.
344
     *
345
     * @return \TechDivision\Import\Repositories\EavAttributeSetRepository The repository instance
346
     */
347
    public function getEavAttributeSetRepository()
348
    {
349
        return $this->eavAttributeSetRepository;
350
    }
351
352
    /**
353
     * Return's the repository to access EAV entity types.
354
     *
355
     * @return \TechDivision\Import\Repositories\EavEntityTypeRepository The repository instance
356
     */
357
    public function getEavEntityTypeRepository()
358
    {
359
        return $this->eavEntityTypeRepository;
360
    }
361
362
    /**
363
     * Set's the repository to access EAV entity types.
364
     *
365
     * @param \TechDivision\Import\Repositories\EavEntityTypeRepository $eavEntityTypeRepository The repository the access EAV entity types
366
     *
367
     * @return void
368
     */
369
    public function setEavEntityTypeRepository($eavEntityTypeRepository)
370
    {
371
        $this->eavEntityTypeRepository = $eavEntityTypeRepository;
372
    }
373
374
    /**
375
     * Set's the repository to access stores.
376
     *
377
     * @param \TechDivision\Import\Repositories\StoreRepository $storeRepository The repository the access stores
378
     *
379
     * @return void
380
     */
381
    public function setStoreRepository($storeRepository)
382
    {
383
        $this->storeRepository = $storeRepository;
384
    }
385
386
    /**
387
     * Return's the repository to access stores.
388
     *
389
     * @return \TechDivision\Import\Repositories\StoreRepository The repository instance
390
     */
391
    public function getStoreRepository()
392
    {
393
        return $this->storeRepository;
394
    }
395
396
    /**
397
     * Set's the repository to access store websites.
398
     *
399
     * @param \TechDivision\Import\Repositories\StoreWebsiteRepository $storeWebsiteRepository The repository the access store websites
400
     *
401
     * @return void
402
     */
403
    public function setStoreWebsiteRepository($storeWebsiteRepository)
404
    {
405
        $this->storeWebsiteRepository = $storeWebsiteRepository;
406
    }
407
408
    /**
409
     * Return's the repository to access store websites.
410
     *
411
     * @return \TechDivision\Import\Repositories\StoreWebsiteRepository The repository instance
412
     */
413
    public function getStoreWebsiteRepository()
414
    {
415
        return $this->storeWebsiteRepository;
416
    }
417
418
    /**
419
     * Set's the repository to access tax classes.
420
     *
421
     * @param \TechDivision\Import\Repositories\TaxClassRepository $taxClassRepository The repository the access stores
422
     *
423
     * @return void
424
     */
425
    public function setTaxClassRepository($taxClassRepository)
426
    {
427
        $this->taxClassRepository = $taxClassRepository;
428
    }
429
430
    /**
431
     * Return's the repository to access tax classes.
432
     *
433
     * @return \TechDivision\Import\Repositories\TaxClassRepository The repository instance
434
     */
435
    public function getTaxClassRepository()
436
    {
437
        return $this->taxClassRepository;
438
    }
439
440
    /**
441
     * Set's the repository to access link types.
442
     *
443
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkTypeRepository The repository to access link types
444
     *
445
     * @return void
446
     */
447
    public function setLinkTypeRepository($linkTypeRepository)
448
    {
449
        $this->linkTypeRepository = $linkTypeRepository;
450
    }
451
452
    /**
453
     * Return's the repository to access link types.
454
     *
455
     * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance
456
     */
457
    public function getLinkTypeRepository()
458
    {
459
        return $this->linkTypeRepository;
460
    }
461
462
    /**
463
     * Set's the repository to access link attributes.
464
     *
465
     * @param \TechDivision\Import\Repositories\LinkTypeRepository $linkAttributeRepository The repository to access link attributes
466
     *
467
     * @return void
468
     */
469
    public function setLinkAttributeRepository($linkAttributeRepository)
470
    {
471
        $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...
472
    }
473
474
    /**
475
     * Return's the repository to access link attributes.
476
     *
477
     * @return \TechDivision\Import\Repositories\LinkTypeRepository The repository instance
478
     */
479
    public function getLinkAttributeRepository()
480
    {
481
        return $this->linkAttributeRepository;
482
    }
483
484
    /**
485
     * Set's the repository to access the Magento 2 configuration.
486
     *
487
     * @param \TechDivision\Import\Repositories\CoreConfigDataRepository $coreConfigDataRepository The repository to access the Magento 2 configuration
488
     *
489
     * @return void
490
     */
491
    public function setCoreConfigDataRepository($coreConfigDataRepository)
492
    {
493
        $this->coreConfigDataRepository = $coreConfigDataRepository;
494
    }
495
496
    /**
497
     * Return's the repository to access the Magento 2 configuration.
498
     *
499
     * @return \TechDivision\Import\Repositories\CoreConfigDataRepository The repository instance
500
     */
501
    public function getCoreConfigDataRepository()
502
    {
503
        return $this->coreConfigDataRepository;
504
    }
505
506
    /**
507
     * Return's the EAV attribute set with the passed ID.
508
     *
509
     * @param integer $id The ID of the EAV attribute set to load
510
     *
511
     * @return array The EAV attribute set
512
     */
513
    public function getEavAttributeSet($id)
514
    {
515
        return $this->getEavAttributeSetRepository()->load($id);
516
    }
517
518
    /**
519
     * Return's the attribute sets for the passed entity type ID.
520
     *
521
     * @param mixed $entityTypeId The entity type ID to return the attribute sets for
522
     *
523
     * @return array|boolean The attribute sets for the passed entity type ID
524
     */
525
    public function getEavAttributeSetsByEntityTypeId($entityTypeId)
526
    {
527
        return $this->getEavAttributeSetRepository()->findAllByEntityTypeId($entityTypeId);
528
    }
529
530
    /**
531
     * Return's an array with the EAV attributes for the passed entity type ID and attribute set name.
532
     *
533
     * @param integer $entityTypeId     The entity type ID of the EAV attributes to return
534
     * @param string  $attributeSetName The attribute set name of the EAV attributes to return
535
     *
536
     * @return array The
537
     */
538
    public function getEavAttributesByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName)
539
    {
540
        return $this->getEavAttributeRepository()->findAllByEntityTypeIdAndAttributeSetName($entityTypeId, $attributeSetName);
541
    }
542
543
    /**
544
     * Return's an array with the available EAV attributes for the passed option value and store ID.
545
     *
546
     * @param string $optionValue The option value of the EAV attributes
547
     * @param string $storeId     The store ID of the EAV attribues
548
     *
549
     * @return array The array with all available EAV attributes
550
     */
551
    public function getEavAttributesByOptionValueAndStoreId($optionValue, $storeId)
552
    {
553
        return $this->getEavAttributeRepository()->findAllByOptionValueAndStoreId($optionValue, $storeId);
554
    }
555
556
    /**
557
     * Return's the first EAV attribute for the passed option value and store ID.
558
     *
559
     * @param string $optionValue The option value of the EAV attributes
560
     * @param string $storeId     The store ID of the EAV attribues
561
     *
562
     * @return array The array with the EAV attribute
563
     */
564
    public function getEavAttributeByOptionValueAndStoreId($optionValue, $storeId)
565
    {
566
        return $this->getEavAttributeRepository()->findOneByOptionValueAndStoreId($optionValue, $storeId);
567
    }
568
569
    /**
570
     * Return's an array with the available EAV attributes for the passed is user defined flag.
571
     *
572
     * @param integer $isUserDefined The flag itself
573
     *
574
     * @return array The array with the EAV attributes matching the passed flag
575
     */
576
    public function getEavAttributesByIsUserDefined($isUserDefined = 1)
577
    {
578
        return $this->getEavAttributeRepository()->findAllByIsUserDefined($isUserDefined);
579
    }
580
581
    /**
582
     * Return's an array with the available EAV attributes for the passed is entity type and
583
     * user defined flag.
584
     *
585
     * @param integer $entityTypeId  The entity type ID of the EAV attributes to return
586
     * @param integer $isUserDefined The flag itself
587
     *
588
     * @return array The array with the EAV attributes matching the passed entity type and user defined flag
589
     */
590
    public function getEavAttributesByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined = 1)
591
    {
592
        return $this->getEavAttributeRepository()->findAllByEntityTypeIdAndIsUserDefined($entityTypeId, $isUserDefined);
593
    }
594
595
    /**
596
     * Return's an array with all available EAV entity types with the entity type code as key.
597
     *
598
     * @return array The available link types
599
     */
600
    public function getEavEntityTypes()
601
    {
602
        return $this->getEavEntityTypeRepository()->findAll();
603
    }
604
605
    /**
606
     * Return's an array with the available stores.
607
     *
608
     * @return array The array with the available stores
609
     */
610
    public function getStores()
611
    {
612
        return $this->getStoreRepository()->findAll();
613
    }
614
615
    /**
616
     * Return's the default store.
617
     *
618
     * @return array The default store
619
     */
620
    public function getDefaultStore()
621
    {
622
        return $this->getStoreRepository()->findOneByDefault();
623
    }
624
625
    /**
626
     * Return's an array with the available store websites.
627
     *
628
     * @return array The array with the available store websites
629
     */
630
    public function getStoreWebsites()
631
    {
632
        return $this->getStoreWebsiteRepository()->findAll();
633
    }
634
635
    /**
636
     * Return's an array with the available tax classes.
637
     *
638
     * @return array The array with the available tax classes
639
     */
640
    public function getTaxClasses()
641
    {
642
        return $this->getTaxClassRepository()->findAll();
643
    }
644
645
    /**
646
     * Return's an array with all available categories.
647
     *
648
     * @return array The available categories
649
     */
650
    public function getCategories()
651
    {
652
        return $this->getCategoryRepository()->findAll();
653
    }
654
655
    /**
656
     * Return's an array with the root categories with the store code as key.
657
     *
658
     * @return array The root categories
659
     */
660
    public function getRootCategories()
661
    {
662
        return $this->getCategoryRepository()->findAllRootCategories();
663
    }
664
665
    /**
666
     * Returns the category varchar values for the categories with
667
     * the passed with the passed entity IDs.
668
     *
669
     * @param array $entityIds The array with the category IDs
670
     *
671
     * @return mixed The category varchar values
672
     */
673
    public function getCategoryVarcharsByEntityIds(array $entityIds)
674
    {
675
        return $this->getCategoryVarcharRepository()->findAllByEntityIds($entityIds);
676
    }
677
678
    /**
679
     * Return's an array with all available link types.
680
     *
681
     * @return array The available link types
682
     */
683
    public function getLinkTypes()
684
    {
685
        return $this->getLinkTypeRepository()->findAll();
686
    }
687
688
    /**
689
     * Return's an array with all available link attributes.
690
     *
691
     * @return array The available link attributes
692
     */
693
    public function getLinkAttributes()
694
    {
695
        return $this->getLinkAttributeRepository()->findAll();
696
    }
697
698
    /**
699
     * Return's an array with the Magento 2 configuration.
700
     *
701
     * @return array The Magento 2 configuration
702
     */
703
    public function getCoreConfigData()
704
    {
705
        return $this->getCoreConfigDataRepository()->findAll();
706
    }
707
708
    /**
709
     * Returns the array with the global data necessary for the
710
     * import process.
711
     *
712
     * @return array The array with the global data
713
     */
714
    public function getGlobalData()
715
    {
716
717
        // initialize the array for the global data
718
        $globalData = array();
719
720
        // initialize the global data
721
        $globalData[RegistryKeys::STORES] = $this->getStores();
722
        $globalData[RegistryKeys::LINK_TYPES] = $this->getLinkTypes();
723
        $globalData[RegistryKeys::TAX_CLASSES] = $this->getTaxClasses();
724
        $globalData[RegistryKeys::DEFAULT_STORE] = $this->getDefaultStore();
725
        $globalData[RegistryKeys::STORE_WEBSITES] = $this->getStoreWebsites();
726
        $globalData[RegistryKeys::LINK_ATTRIBUTES] = $this->getLinkAttributes();
727
        $globalData[RegistryKeys::ROOT_CATEGORIES] = $this->getRootCategories();
728
        $globalData[RegistryKeys::CORE_CONFIG_DATA] = $this->getCoreConfigData();
729
        $globalData[RegistryKeys::ENTITY_TYPES] = $eavEntityTypes = $this->getEavEntityTypes();
730
731
        // prepare the attribute sets
732
        $eavAttributes = array();
733
        $eavAttributeSets = array();
734
        foreach ($eavEntityTypes as $eavEntityTypeCode => $eavEntityType) {
735
            // load the attribute sets for the entity type
736
            $attributeSets = $this->getEavAttributeSetsByEntityTypeId($entityTypeId = $eavEntityType[MemberNames::ENTITY_TYPE_ID]);
737
            // append the attribute sets to the array
738
            $eavAttributeSets[$eavEntityTypeCode] = $attributeSets;
739
740
            // iterate over the attribute sets and initialize the attributes
741
            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...
742
                // load the attribute set name
743
                $eavAttributeSetName = $attributeSet[MemberNames::ATTRIBUTE_SET_NAME];
744
                // load the attributes for the attribute set
745
                $eavAttributes[$eavEntityTypeCode][$eavAttributeSetName] = $this->getEavAttributesByEntityTypeIdAndAttributeSetName(
746
                    $entityTypeId,
747
                    $eavAttributeSetName
748
                );
749
            }
750
        }
751
752
        // prepare the user defined attributes
753
        $eavUserDefinedAttributes = array();
754
        foreach ($eavEntityTypes as $eavEntityTypeCode => $eavEntityType) {
755
            // load the user defined attributes for the entity type
756
            $eavUserDefinedAttributes[$eavEntityTypeCode] = $this->getEavAttributesByEntityTypeIdAndIsUserDefined(
757
                $eavEntityType[MemberNames::ENTITY_TYPE_ID]
758
            );
759
        }
760
761
        // initialize the arrays with the EAV attributes, EAV user defined attributes and attribute sets
762
        $globalData[RegistryKeys::EAV_ATTRIBUTES] = $eavAttributes;
763
        $globalData[RegistryKeys::ATTRIBUTE_SETS] = $eavAttributeSets;
764
        $globalData[RegistryKeys::EAV_USER_DEFINED_ATTRIBUTES] = $eavUserDefinedAttributes;
765
766
        // initialize the array with the avaliable categories
767
        $globalData[RegistryKeys::CATEGORIES] = $this->categoryAssembler->getCategoriesWithResolvedPath();
768
769
        // return the array
770
        return $globalData;
771
    }
772
}
773