MoveLocalizedAttributesToAttributes   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A translate() 0 17 5
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 MoveLocalizedAttributesToAttributes extends AbstractTranslatorFunction implements TranslatorFunctionInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    public const KEY_ATTRIBUTES = 'attributes';
19
20
    /**
21
     * @var string
22
     */
23
    public const ATTRIBUTE_BLACKLIST = 'blacklist';
24
25
    /**
26
     * @var array
27
     */
28
    protected $requiredOptions = [
29
        self::ATTRIBUTE_BLACKLIST,
30
    ];
31
32
    /**
33
     * @param mixed $value
34
     * @param array $payload
35
     *
36
     * @return array
37
     */
38
    public function translate($value, array $payload): array
39
    {
40
        foreach ($value as $localeId => $scopedAttributes) {
41
            if (!isset($value[$localeId][static::KEY_ATTRIBUTES])) {
42
                $value[$localeId][static::KEY_ATTRIBUTES] = [];
43
            }
44
            foreach ($scopedAttributes as $attributeKey => $attribute) {
45
                if (in_array($attributeKey, $this->options[static::ATTRIBUTE_BLACKLIST])) {
46
                    continue;
47
                }
48
49
                $value[$localeId][static::KEY_ATTRIBUTES][$attributeKey] = $attribute;
50
                unset($value[$localeId][$attributeKey]);
51
            }
52
        }
53
54
        return $value;
55
    }
56
}
57