AddAttributeValues   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A translate() 0 17 4
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 AddAttributeValues extends AbstractTranslatorFunction implements TranslatorFunctionInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    protected const KEY_OPTIONS = 'options';
19
20
    /**
21
     * @var string
22
     */
23
    protected const KEY_VALUES = 'values';
24
25
    /**
26
     * @var string
27
     */
28
    protected const KEY_VALUE_TRANSLATIONS = 'value_translations';
29
30
    /**
31
     * @param mixed $value
32
     * @param array $payload
33
     *
34
     * @return mixed
35
     */
36
    public function translate($value, array $payload)
37
    {
38
        foreach ($value as $inputValueKey => $item) {
39
            $item[static::KEY_VALUES] = array_keys($payload[static::KEY_OPTIONS]);
40
            $item[static::KEY_VALUE_TRANSLATIONS] = [];
41
            foreach ($payload[static::KEY_OPTIONS] as $optionKey => $optionValue) {
42
                if (isset($optionValue[$inputValueKey])) {
43
                    $item[static::KEY_VALUE_TRANSLATIONS][$optionKey] = $optionValue[$inputValueKey];
44
45
                    continue;
46
                }
47
                $item[static::KEY_VALUE_TRANSLATIONS][$optionKey] = $optionKey;
48
            }
49
            $value[$inputValueKey] = $item;
50
        }
51
52
        return $value;
53
    }
54
}
55