LabelsToLocalizedAttributeNames   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 15
c 2
b 0
f 1
dl 0
loc 43
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 22 4
A getLocales() 0 3 1
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 LabelsToLocalizedAttributeNames extends AbstractTranslatorFunction implements TranslatorFunctionInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    protected const KEY_NAME = 'name';
19
20
    /**
21
     * @param mixed $value
22
     * @param array $payload
23
     *
24
     * @return mixed
25
     */
26
    public function translate($value, array $payload)
27
    {
28
        $defaultLocales = $this->getLocales();
29
30
        $key = $this->options['key'] ?? static::KEY_NAME;
31
32
        if (!$value && $defaultLocales) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $defaultLocales of type array 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...
introduced by
$defaultLocales is an empty array, thus is always false.
Loading history...
33
            $code = $payload['category_key'];
34
            foreach ($defaultLocales as $locale) {
35
                $value[$locale] = [
36
                    $key => $code,
37
                ];
38
            }
39
40
            return $value;
41
        }
42
43
        return array_map(function ($value) use ($key) {
44
            return [
45
                $key => $value,
46
            ];
47
        }, $value);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    protected function getLocales(): array
54
    {
55
        return $this->options['defaultLocales'] ?? [];
56
    }
57
}
58