LabelsToLocaleIds   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 20 5
A getMap() 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 LabelsToLocaleIds extends AbstractTranslatorFunction implements TranslatorFunctionInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $requiredOptions = [
19
        'map',
20
    ];
21
22
    /**
23
     * @param mixed $value
24
     * @param array $payload
25
     *
26
     * @return mixed
27
     */
28
    public function translate($value, array $payload)
29
    {
30
        if ($value === null) {
31
            return $value;
32
        }
33
34
        if (!$value) {
35
            $value = $this->getMap();
36
        }
37
38
        $result = [];
39
        $localeMap = $this->getMap();
40
41
        foreach ($value as $locale => $content) {
42
            if (array_key_exists($locale, $localeMap)) {
43
                $result[$locale] = $localeMap[$locale];
44
            }
45
        }
46
47
        return $result;
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    protected function getMap(): array
54
    {
55
        return $this->options['map'];
56
    }
57
}
58