Conditions | 11 |
Paths | 26 |
Total Lines | 56 |
Code Lines | 31 |
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 |
||
28 | public function mapArticles($csv) |
||
29 | { |
||
30 | $articles = []; |
||
31 | foreach ($csv as $key => $entry) { |
||
32 | if (strpos($entry['Artikelnummer'], '_1') !== false) { |
||
33 | continue; |
||
34 | } |
||
35 | $article = $this->getArticleArray($entry); |
||
36 | if ($csv[$key + 1]['Artikelnummer'] === $entry['Artikelnummer'] . '_1') { |
||
37 | $secondLine = $csv[$key + 1]; |
||
38 | $secondLine['Artikelnummer'] = str_replace('_1', '', $secondLine['Artikelnummer']); |
||
39 | $articleExtended = $this->getArticleArray($secondLine); |
||
40 | |||
41 | $article['variants'] = array_merge($article['variants'], $articleExtended['variants']); |
||
42 | |||
43 | $groupKeys = array_keys($article['configuratorSet']['groups']); |
||
44 | if (is_array($groupKeys)) { |
||
45 | foreach ($groupKeys as $groupKey) { |
||
46 | $article['configuratorSet']['groups'][$groupKey]['options'] = array_merge( |
||
47 | $article['configuratorSet']['groups'][$groupKey]['options'], |
||
48 | $articleExtended['configuratorSet']['groups'][$groupKey]['options'] |
||
49 | ); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | // if in the first row no variant has a stock but the second row |
||
54 | if ($article['mainDetail']['number'] === false && !empty($articleExtended['mainDetail']['number'])) { |
||
55 | $article['mainDetail']['number'] = $articleExtended['mainDetail']['number']; |
||
56 | } |
||
57 | |||
58 | // we need at least one default order number ;-) |
||
59 | if ($article['mainDetail']['number'] === false) { |
||
60 | $stockArray = ArticleUtil::getKeyValueArray($entry['Bestand']); |
||
61 | $article['mainDetail']['number'] = ArticleUtil::convertOrderNumber( |
||
62 | $entry['Artikelnummer'] . '-' . key($stockArray) |
||
63 | ); |
||
64 | foreach ($article['variants'] as &$value) { |
||
65 | if ($value['number'] === $article['mainDetail']['number']) { |
||
66 | $value['isMain'] = true; |
||
67 | break; |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | // testing category |
||
73 | $article['categories'][] = [ |
||
74 | 'id' => 4 |
||
75 | ]; |
||
76 | |||
77 | |||
78 | $articles[] = $article; |
||
79 | } |
||
80 | |||
81 | return $articles; |
||
82 | |||
83 | } |
||
84 | |||
179 |