| Conditions | 15 |
| Paths | 394 |
| Total Lines | 59 |
| Code Lines | 36 |
| 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 |
||
| 144 | protected function renderItems() |
||
| 145 | { |
||
| 146 | $headers = []; |
||
| 147 | $panes = []; |
||
| 148 | |||
| 149 | if (!$this->hasActiveTab() && !empty($this->items)) { |
||
| 150 | $this->items[0]['active'] = true; |
||
| 151 | } |
||
| 152 | |||
| 153 | foreach ($this->items as $index => $item) { |
||
| 154 | if (!array_key_exists('label', $item)) { |
||
| 155 | throw new InvalidConfigException("The 'label' option is required."); |
||
| 156 | } elseif (ArrayHelper::remove($item, 'visible', true)) { |
||
| 157 | $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; |
||
| 158 | $label = $encodeLabel ? Html::encode($item['label']) : $item['label']; |
||
| 159 | $headerOptions = array_merge($this->headerOptions, ArrayHelper::getValue($item, 'headerOptions', [])); |
||
| 160 | $linkOptions = array_merge($this->linkOptions, ArrayHelper::getValue($item, 'linkOptions', [])); |
||
| 161 | $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', [])); |
||
| 162 | $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-tab' . $index); |
||
| 163 | |||
| 164 | Html::addCssClass($options, 'col s12'); |
||
| 165 | |||
| 166 | // Add active tab and content |
||
| 167 | if (ArrayHelper::remove($item, 'active')) { |
||
| 168 | Html::addCssClass($options, 'active'); |
||
| 169 | Html::addCssClass($headerOptions, ['active', 'tab']); |
||
| 170 | } else { |
||
| 171 | Html::addCssClass($headerOptions, 'tab'); |
||
| 172 | } |
||
| 173 | |||
| 174 | // Add disabled tab and content |
||
| 175 | if (ArrayHelper::remove($item, 'disabled')) { |
||
| 176 | Html::addCssClass($headerOptions, 'disabled'); |
||
| 177 | } |
||
| 178 | |||
| 179 | // Add tab header |
||
| 180 | if (isset($item['url'])) { |
||
| 181 | $linkOptions['target'] = isset($linkOptions['target']) ? $linkOptions['target'] : '_self'; |
||
| 182 | $header = Html::a($label, $item['url'], $linkOptions); |
||
| 183 | } else { |
||
| 184 | $header = Html::a($label, '#' . $options['id'], $linkOptions); |
||
| 185 | } |
||
| 186 | |||
| 187 | // Add tab content |
||
| 188 | if ($this->renderTabContent) { |
||
| 189 | $tag = ArrayHelper::remove($options, 'tag', 'div'); |
||
| 190 | $panes[] = Html::tag($tag, isset($item['content']) ? $item['content'] : '', $options); |
||
| 191 | } |
||
| 192 | |||
| 193 | $headers[] = Html::tag('li', $header, $headerOptions); |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | $html = Html::tag('ul', implode("\n", $headers), $this->options); |
||
| 198 | $html .= $this->renderTabContent |
||
| 199 | ? "\n" . Html::tag('div', implode("\n", $panes), ['class' => 'tab-content']) |
||
| 200 | : ''; |
||
| 201 | |||
| 202 | return $html; |
||
| 203 | } |
||
| 220 |