AddAbstractSkuIfNotExist::translate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
rs 10
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\AkeneoPimMiddlewareConnector\Business\Translator\TranslatorFunction;
9
10
use SprykerMiddleware\Zed\Process\Business\Translator\TranslatorFunction\AbstractTranslatorFunction;
0 ignored issues
show
Bug introduced by
The type SprykerMiddleware\Zed\Pr...tractTranslatorFunction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SprykerMiddleware\Zed\Process\Business\Translator\TranslatorFunction\TranslatorFunctionInterface;
0 ignored issues
show
Bug introduced by
The type SprykerMiddleware\Zed\Pr...slatorFunctionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
class AddAbstractSkuIfNotExist extends AbstractTranslatorFunction implements TranslatorFunctionInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    protected const KEY_PARENT = 'parent';
19
20
    /**
21
     * @var string
22
     */
23
    protected const KEY_CODE = 'code';
24
25
    /**
26
     * @var string
27
     */
28
    protected const KEY_IDENTIFIER = 'identifier';
29
30
    /**
31
     * @var string
32
     */
33
    protected const KEY_ABSTRACT_SKU = 'abstract_sku';
34
35
    /**
36
     * @var string
37
     */
38
    protected const ABSTRACT_IDENTIFIER = 'abstract_product_creation';
39
40
    /**
41
     * @param mixed $value
42
     * @param array $payload
43
     *
44
     * @return mixed
45
     */
46
    public function translate($value, array $payload)
47
    {
48
        if ($payload[static::KEY_PARENT] === null) {
49
            $value[static::KEY_ABSTRACT_SKU] = $this->createAbstractSKU($payload[static::KEY_IDENTIFIER]);
50
            $value[static::ABSTRACT_IDENTIFIER] = true;
51
52
            return $value;
53
        }
54
55
        $value = [];
56
        $value[static::KEY_ABSTRACT_SKU] = $payload[static::KEY_PARENT];
57
        $value[static::ABSTRACT_IDENTIFIER] = false;
58
59
         return $value;
60
    }
61
62
    /**
63
     * @param string $sku
64
     *
65
     * @return string
66
     */
67
    protected function createAbstractSKU(string $sku): string
68
    {
69
        return $sku . '_abstract';
70
    }
71
}
72