| Conditions | 12 |
| Paths | 12 |
| Total Lines | 22 |
| Code Lines | 17 |
| 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 |
||
| 56 | protected function renderItem($item) |
||
| 57 | { |
||
| 58 | $item['badgeOptions'] = isset($item['badgeOptions']) ? $item['badgeOptions'] : []; |
||
| 59 | if (!ArrayHelper::getValue($item, 'badgeOptions.class')) { |
||
| 60 | $bg = isset($item['badgeBgClass']) ? $item['badgeBgClass'] : $this->badgeBgClass; |
||
| 61 | $item['badgeOptions']['class'] = $this->badgeClass . ' ' . $bg; |
||
| 62 | } |
||
| 63 | if (isset($item['items']) && !isset($item['right-icon'])) { |
||
| 64 | $item['right-icon'] = $this->parentRightIcon; |
||
| 65 | } |
||
| 66 | $template = ArrayHelper::getValue( |
||
| 67 | $item, |
||
| 68 | 'template', |
||
| 69 | isset($item['url']) ? $this->linkTemplate : $this->labelTemplate |
||
| 70 | ); |
||
| 71 | return strtr($template, [ |
||
| 72 | '{badge}' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', |
||
| 73 | '{icon}' => isset($item['icon']) ? $item['icon'] : '', |
||
| 74 | '{right-icon}' => isset($item['right-icon']) ? $item['right-icon'] : '', |
||
| 75 | '{url}' => isset($item['url']) ? Url::to($item['url']) : '', |
||
| 76 | '{label}' => $item['label'], |
||
| 77 | '{linkOptions}' => isset($item['linkOptions']) ? Html::renderTagAttributes($item['linkOptions']) : '', |
||
| 78 | ]); |
||
| 81 |