AddProductAttributeKeysStep::execute()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 22
rs 9.8666
cc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace Pyz\Zed\DataImport\Business\Model\ProductAttributeKey;
11
12
use Orm\Zed\Product\Persistence\Map\SpyProductAttributeKeyTableMap;
13
use Orm\Zed\Product\Persistence\SpyProductAttributeKeyQuery;
14
use Propel\Runtime\Formatter\SimpleArrayFormatter;
15
use Spryker\Zed\DataImport\Business\Model\DataImportStep\DataImportStepInterface;
16
use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface;
17
18
class AddProductAttributeKeysStep implements DataImportStepInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    public const KEY_TARGET = 'attributeKeys';
24
25
    /**
26
     * @var array<string, int>
27
     */
28
    protected $productAttributeKeys = [];
29
30
    /**
31
     * @param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet
32
     *
33
     * @return void
34
     */
35
    public function execute(DataSetInterface $dataSet): void
36
    {
37
        if (!$this->productAttributeKeys) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->productAttributeKeys of type array<string,integer> is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
38
            $query = SpyProductAttributeKeyQuery::create()
39
                ->select([
40
                    SpyProductAttributeKeyTableMap::COL_ID_PRODUCT_ATTRIBUTE_KEY,
41
                    SpyProductAttributeKeyTableMap::COL_KEY,
42
                ])
43
                ->setFormatter(new SimpleArrayFormatter());
44
45
            /** @var array<array<string, mixed>> $productAttributeKeys */
46
            $productAttributeKeys = $query->find();
47
            foreach ($productAttributeKeys as $productAttributeKey) {
48
                /** @var string $key */
49
                $key = $productAttributeKey[SpyProductAttributeKeyTableMap::COL_KEY];
50
                $value = $productAttributeKey[SpyProductAttributeKeyTableMap::COL_ID_PRODUCT_ATTRIBUTE_KEY];
51
52
                $this->productAttributeKeys[$key] = $value;
53
            }
54
        }
55
56
        $dataSet[static::KEY_TARGET] = $this->productAttributeKeys;
57
    }
58
}
59