Conditions | 3 |
Paths | 3 |
Total Lines | 54 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
124 | private function attachArticleVariants(&$articleArray, $article) |
||
125 | { |
||
126 | $stock = ArticleUtil::getKeyValueArray($article['Bestand']); |
||
127 | |||
128 | if (key($stock) === '-') { |
||
129 | return; |
||
130 | } |
||
131 | |||
132 | $ean = ArticleUtil::getKeyValueArray($article['EAN']); |
||
133 | |||
134 | $groupOptions = []; |
||
135 | $variants = []; |
||
136 | |||
137 | foreach ($stock as $size => $value) { |
||
138 | $variantNumber = ArticleUtil::convertOrderNumber($article['Artikelnummer'] . '-' . $size); |
||
139 | $variants[] = |
||
140 | [ |
||
141 | 'isMain' => $variantNumber === $articleArray['mainDetail']['number'], |
||
142 | 'number' => $variantNumber, |
||
143 | 'ean' => $ean[$size], |
||
144 | 'active' => $stock[$size] > 0, |
||
145 | 'inStock' => $stock[$size], |
||
146 | 'additionalText' => $size, |
||
147 | 'configuratorOptions' => [ |
||
148 | [ |
||
149 | 'group' => $this->groupName, |
||
150 | 'option' => $size |
||
151 | ] |
||
152 | ], |
||
153 | 'prices' => [ |
||
154 | [ |
||
155 | 'price' => ArticleUtil::convertPrice($article['Preis']), |
||
156 | 'pseudoPrice' => ArticleUtil::convertPrice($article['VKS']) |
||
157 | ], |
||
158 | ], |
||
159 | ]; |
||
160 | |||
161 | // add configurator set |
||
162 | $groupOptions[] = ['name' => $size]; |
||
163 | |||
164 | } |
||
165 | // add configurator set |
||
166 | $articleArray['configuratorSet'] = [ |
||
167 | 'type' => 1, |
||
168 | 'groups' => [ |
||
169 | [ |
||
170 | 'name' => $this->groupName, |
||
171 | 'options' => $groupOptions |
||
172 | ] |
||
173 | ] |
||
174 | ]; |
||
175 | |||
176 | $articleArray['variants'] = $variants; |
||
177 | } |
||
178 | } |
||
179 |