Conditions | 15 |
Paths | 24 |
Total Lines | 32 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
83 | protected function renderItem($item) |
||
84 | { |
||
85 | $item['badgeOptions'] = isset($item['badgeOptions']) ? $item['badgeOptions'] : []; |
||
86 | if (!ArrayHelper::getValue($item, 'badgeOptions.class')) { |
||
87 | $bg = isset($item['badgeBgClass']) ? $item['badgeBgClass'] : $this->badgeBgClass; |
||
88 | $item['badgeOptions']['class'] = $this->badgeClass . ' ' . $bg; |
||
89 | } |
||
90 | if (isset($item['items']) && !isset($item['right-icon'])) { |
||
91 | $item['right-icon'] = $this->parentRightIcon; |
||
92 | } |
||
93 | if (isset($item['url'])) { |
||
94 | $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate); |
||
95 | return strtr($template, [ |
||
96 | '{badge}' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', |
||
97 | '{icon}' => isset($item['icon']) ? $item['icon'] : '', |
||
98 | '{right-icon}' => isset($item['right-icon']) ? $item['right-icon'] : '', |
||
99 | '{url}' => Url::to($item['url']), |
||
100 | '{label}' => $item['label'], |
||
101 | '{linkOptions}' => isset($item['linkOptions']) ? Html::renderTagAttributes($item['linkOptions']): '', |
||
102 | ]); |
||
103 | } else { |
||
104 | $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate); |
||
105 | return strtr($template, [ |
||
106 | '{badge}' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', |
||
107 | '{icon}' => isset($item['icon']) ? $item['icon'] : '', |
||
108 | '{right-icon}' => isset($item['right-icon']) ? $item['right-icon'] : '', |
||
109 | '{label}' => $item['label'], |
||
110 | '{linkOptions}' => isset($item['linkOptions']) ? Html::renderTagAttributes($item['linkOptions']): '', |
||
111 | ]); |
||
112 | |||
113 | } |
||
114 | } |
||
115 | } |