| Conditions | 2 |
| Paths | 2 |
| Total Lines | 60 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 43 | protected function setupListOperation() |
||
| 44 | { |
||
| 45 | CRUD::addColumn([ |
||
| 46 | 'name' => 'enrollment.student', |
||
| 47 | 'key' => 'student_lastname', |
||
| 48 | 'attribute' => 'lastname', |
||
| 49 | 'label' => __('Last Name'), |
||
| 50 | 'type' => 'relationship', |
||
| 51 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
| 52 | $query->orWhereHas('enrollment', function ($q) use ($searchTerm) { |
||
| 53 | $q->whereHas('user', function ($q) use ($searchTerm) { |
||
| 54 | $q->where('lastname', 'like', '%'.$searchTerm.'%'); |
||
| 55 | }); |
||
| 56 | }); |
||
| 57 | }, |
||
| 58 | ]); |
||
| 59 | |||
| 60 | CRUD::addColumn([ |
||
| 61 | 'name' => 'enrollment.student', |
||
| 62 | 'key' => 'student_firstname', |
||
| 63 | 'attribute' => 'firstname', |
||
| 64 | 'label' => __('First Name'), |
||
| 65 | 'type' => 'relationship', |
||
| 66 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
| 67 | $query->orWhereHas('enrollment', function ($q) use ($searchTerm) { |
||
| 68 | $q->whereHas('user', function ($q) use ($searchTerm) { |
||
| 69 | $q->where('firstname', 'like', '%'.$searchTerm.'%'); |
||
| 70 | }); |
||
| 71 | }); |
||
| 72 | }, |
||
| 73 | ]); |
||
| 74 | |||
| 75 | |||
| 76 | CRUD::addColumn([ |
||
| 77 | 'name' => 'enrollment.student', |
||
| 78 | 'key' => 'student_email', |
||
| 79 | 'attribute' => 'email', |
||
| 80 | 'label' => __('Email'), |
||
| 81 | 'type' => 'relationship', |
||
| 82 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
| 83 | $query->orWhereHas('enrollment', function ($q) use ($searchTerm) { |
||
| 84 | $q->whereHas('user', function ($q) use ($searchTerm) { |
||
| 85 | $q->where('email', 'like', '%'.$searchTerm.'%'); |
||
| 86 | }); |
||
| 87 | }); |
||
| 88 | }, |
||
| 89 | ]); |
||
| 90 | |||
| 91 | if (config('app.currency_position') === 'before') { |
||
| 92 | $currency = array('prefix' => config('app.currency_symbol')); |
||
| 93 | } else { |
||
| 94 | $currency = array('suffix' => config('app.currency_symbol')); |
||
| 95 | } |
||
| 96 | |||
| 97 | CRUD::addColumn(array_merge([ |
||
| 98 | 'name' => 'value', |
||
| 99 | 'label' => __('Value'), |
||
| 100 | 'type' => 'number'], $currency)); |
||
| 101 | |||
| 102 | CRUD::column('date'); |
||
| 103 | |||
| 142 |