ProductImportDictionary::getDictionary()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 94
Code Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 59
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 94
rs 8.8945

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