| Conditions | 4 |
| Paths | 2 |
| Total Lines | 54 |
| 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 |
||
| 41 | public function render() |
||
| 42 | { |
||
| 43 | if (!$this->grid->showColumnSelector()) { |
||
| 44 | return ''; |
||
| 45 | } |
||
| 46 | |||
| 47 | $show = $this->grid->visibleColumnNames(); |
||
| 48 | |||
| 49 | $lists = $this->getGridColumns()->map(function ($label, $key) use ($show) { |
||
| 50 | if (empty($show)) { |
||
| 51 | $checked = 'checked'; |
||
| 52 | } else { |
||
| 53 | $checked = in_array($key, $show) ? 'checked' : ''; |
||
| 54 | } |
||
| 55 | |||
| 56 | return <<<HTML |
||
| 57 | <li class="checkbox icheck" style="margin: 0;"> |
||
| 58 | <label style="width: 100%;padding: 3px;"> |
||
| 59 | <input type="checkbox" class="column-select-item" value="{$key}" {$checked}/> {$label} |
||
| 60 | </label> |
||
| 61 | </li> |
||
| 62 | HTML; |
||
| 63 | })->implode("\r\n"); |
||
| 64 | |||
| 65 | $btns = [ |
||
| 66 | 'all' => __('admin.all'), |
||
| 67 | 'submit' => __('admin.submit'), |
||
| 68 | ]; |
||
| 69 | |||
| 70 | $this->setupScript(); |
||
| 71 | |||
| 72 | return <<<EOT |
||
| 73 | |||
| 74 | <div class="dropdown pull-right column-selector" style="margin-right: 10px"> |
||
| 75 | <button type="button" class="btn btn-sm btn-instagram dropdown-toggle" data-toggle="dropdown"> |
||
| 76 | <i class="fa fa-table"></i> |
||
| 77 | |
||
| 78 | <span class="caret"></span> |
||
| 79 | </button> |
||
| 80 | <ul class="dropdown-menu" role="menu" style="padding: 10px;"> |
||
| 81 | <li> |
||
| 82 | <ul style='padding: 0;'> |
||
| 83 | {$lists} |
||
| 84 | </ul> |
||
| 85 | </li> |
||
| 86 | <li class="divider"></li> |
||
| 87 | <li class="text-right"> |
||
| 88 | <button class="btn btn-sm btn-default column-select-all">{$btns['all']}</button> |
||
| 89 | <button class="btn btn-sm btn-primary column-select-submit">{$btns['submit']}</button> |
||
| 90 | </li> |
||
| 91 | </ul> |
||
| 92 | </div> |
||
| 93 | EOT; |
||
| 94 | } |
||
| 95 | |||
| 180 |