getDictionary()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 97
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 58
c 2
b 0
f 1
nc 1
nop 0
dl 0
loc 97
rs 8.9163

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Dictionary;
9
10
use SprykerEco\Zed\AkeneoPimMiddlewareConnector\AkeneoPimMiddlewareConnectorConfig;
11
use SprykerMiddleware\Zed\Process\Business\Translator\Dictionary\AbstractDictionary;
0 ignored issues
show
Bug introduced by
The type SprykerMiddleware\Zed\Pr...nary\AbstractDictionary 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 DefaultProductModelImportDictionary extends AbstractDictionary
14
{
15
    /**
16
     * @var array
17
     */
18
    protected static $localeMap;
19
20
    /**
21
     * @var array
22
     */
23
    protected static $attributeMap;
24
25
    /**
26
     * @var \SprykerEco\Zed\AkeneoPimMiddlewareConnector\AkeneoPimMiddlewareConnectorConfig
27
     */
28
    private $config;
29
30
    /**
31
     * @param \SprykerEco\Zed\AkeneoPimMiddlewareConnector\AkeneoPimMiddlewareConnectorConfig $config
32
     */
33
    public function __construct(AkeneoPimMiddlewareConnectorConfig $config)
34
    {
35
        $this->config = $config;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function getDictionary(): array
42
    {
43
        return [
44
            'categories' => [
45
                [
46
                    'ArrayToString',
47
                    'options' => [
48
                        'glue' => ',',
49
                    ],
50
                ],
51
            ],
52
            'values.*' => 'MeasureUnitToInt',
53
            'values.collection.data' => function ($value) {
54
                if (is_array($value)) {
55
                    return reset($value);
56
                }
57
58
                return $value;
59
            },
60
            'values' => [
61
                [
62
                    'EnrichAttributes',
63
                    'options' => [
64
                        'map' => $this->getAttributeMap(),
65
                        'excludeKeys' => [
66
                            'country_availability',
67
                        ],
68
                    ],
69
                ],
70
                [
71
                    'ValuesToAttributes',
72
                    'options' => [
73
                        'locales' => $this->config->getLocalesForImport(),
74
                    ],
75
                ],
76
                [
77
                    'DefaultValuesToLocalizedAttributes',
78
                    'options' => [
79
                        'locales' => $this->config->getLocalesForImport(),
80
                    ],
81
                ],
82
            ],
83
            'values.localizedAttributes' => [
84
                [
85
                    'AddMissingLocales',
86
                    'options' => [
87
                        'locales' => $this->config->getLocalesForImport(),
88
                    ],
89
                ],
90
                [
91
                    'LocaleKeysToIds',
92
                    'options' => [
93
                        'map' => $this->getLocaleMap(),
94
                    ],
95
                ],
96
                [
97
                    'MoveLocalizedAttributesToAttributes',
98
                    'options' => [
99
                        'blacklist' => [
100
                            'name',
101
                            'title',
102
                            'product_description',
103
                            'meta_keywords',
104
                            'meta_title',
105
                            'meta_description',
106
                            'tax_set',
107
                            'is_active_per_locale',
108
                            'bild_information',
109
                            'picto_informationen',
110
                        ],
111
                    ],
112
                ],
113
            ],
114
            'values.localizedAttributes.*' => [
115
                [
116
                    'AddMissingAttributes',
117
                    'options' => [
118
                        'attributes' => [
119
                            'name' => '',
120
                            'description' => '',
121
                            'meta_title' => '',
122
                            'meta_description' => '',
123
                            'meta_keywords' => '',
124
                        ],
125
                    ],
126
                ],
127
                [
128
                    'AddUrlToLocalizedAttributes',
129
                ],
130
            ],
131
            'values.attributes' => [
132
                [
133
                    'ExcludeKeysAssociativeFilter',
134
                    'options' => [
135
                        'excludeKeys' => [
136
                            'price',
137
                            'country_availability',
138
                        ],
139
                    ],
140
                ],
141
            ],
142
        ];
143
    }
144
145
    /**
146
     * @return array
147
     */
148
    protected function getLocaleMap(): array
149
    {
150
        if (static::$localeMap === null) {
0 ignored issues
show
introduced by
The condition static::localeMap === null is always false.
Loading history...
151
            $content = file_get_contents($this->config->getLocaleMapFilePath());
152
            static::$localeMap = json_decode($content, true);
153
        }
154
155
        return static::$localeMap;
156
    }
157
158
    /**
159
     * @return array
160
     */
161
    protected function getAttributeMap(): array
162
    {
163
        if (static::$attributeMap === null) {
0 ignored issues
show
introduced by
The condition static::attributeMap === null is always false.
Loading history...
164
            $content = file_get_contents($this->config->getAttributeMapFilePath());
165
            static::$attributeMap = json_decode($content, true);
166
        }
167
168
        return static::$attributeMap;
169
    }
170
}
171