| Conditions | 2 |
| Paths | 1 |
| Total Lines | 53 |
| 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 |
||
| 69 | protected function grid() |
||
| 70 | { |
||
| 71 | return Admin::grid(User::class, function (Grid $grid) { |
||
| 72 | $grid->id('ID')->sortable(); |
||
| 73 | |||
| 74 | $grid->username(); |
||
| 75 | $grid->email(); |
||
| 76 | $grid->mobile(); |
||
| 77 | $grid->full_name(); |
||
| 78 | $grid->avatar()->display(function ($avatar) { |
||
| 79 | return "<img src='{$avatar}' />"; |
||
| 80 | }); |
||
| 81 | $grid->profile()->postcode('Post code'); |
||
| 82 | $grid->profile()->address(); |
||
| 83 | $grid->position('Position'); |
||
| 84 | $grid->column('profile.color'); |
||
| 85 | $grid->profile()->start_at('开始时间'); |
||
| 86 | $grid->profile()->end_at('结束时间'); |
||
| 87 | |||
| 88 | $grid->column('column1_not_in_table')->display(function () { |
||
| 89 | return 'full name:'.$this->full_name; |
||
| 90 | }); |
||
| 91 | |||
| 92 | $grid->column('column2_not_in_table')->display(function () { |
||
| 93 | return $this->email.'#'.$this->profile['color']; |
||
| 94 | }); |
||
| 95 | |||
| 96 | $grid->tags()->display(function ($tags) { |
||
| 97 | $tags = collect($tags)->map(function ($tag) { |
||
| 98 | return "<code>{$tag['name']}</code>"; |
||
| 99 | })->toArray(); |
||
| 100 | |||
| 101 | return implode('', $tags); |
||
| 102 | }); |
||
| 103 | |||
| 104 | $grid->created_at(); |
||
| 105 | $grid->updated_at(); |
||
| 106 | |||
| 107 | $grid->filter(function ($filter) { |
||
| 108 | $filter->like('username'); |
||
| 109 | $filter->like('email'); |
||
| 110 | $filter->like('profile.postcode'); |
||
| 111 | $filter->between('profile.start_at')->datetime(); |
||
| 112 | $filter->between('profile.end_at')->datetime(); |
||
| 113 | }); |
||
| 114 | |||
| 115 | $grid->actions(function ($actions) { |
||
| 116 | if ($actions->getKey() % 2 == 0) { |
||
| 117 | $actions->append('<a href="/" class="btn btn-xs btn-danger">detail</a>'); |
||
| 118 | } |
||
| 119 | }); |
||
| 120 | }); |
||
| 121 | } |
||
| 122 | |||
| 165 |