| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| Code Lines | 55 |
| 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 |
||
| 42 | public function setupListOperation() |
||
| 43 | { |
||
| 44 | CRUD::setColumns([ |
||
| 45 | [ |
||
| 46 | 'name' => 'id', |
||
| 47 | 'label' => 'ID', |
||
| 48 | ], |
||
| 49 | [ |
||
| 50 | // STUDENT NAME |
||
| 51 | 'label' => __('Student'), |
||
| 52 | 'type' => 'select', |
||
| 53 | 'name' => 'student', |
||
| 54 | 'attribute' => 'name', |
||
| 55 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
| 56 | $query->orWhereHas('student', function ($q) use ($searchTerm) { |
||
| 57 | $q->WhereHas('user', function ($q) use ($searchTerm) { |
||
| 58 | $q->where('firstname', 'like', '%'.$searchTerm.'%') |
||
| 59 | ->orWhere('lastname', 'like', '%'.$searchTerm.'%') |
||
| 60 | ->orWhere('email', 'like', '%'.$searchTerm.'%') |
||
| 61 | ->orWhere('idnumber', 'like', '%'.$searchTerm.'%'); |
||
| 62 | }); |
||
| 63 | }); |
||
| 64 | }, |
||
| 65 | ], |
||
| 66 | [ |
||
| 67 | // COURSE NAME |
||
| 68 | 'label' => __('Course'), |
||
| 69 | 'type' => 'relationship', |
||
| 70 | 'name' => 'course', |
||
| 71 | 'attribute' => 'name', |
||
| 72 | 'model' => Course::class, |
||
| 73 | ], |
||
| 74 | [ |
||
| 75 | 'name' => 'course.period', |
||
| 76 | 'label' => __('Period'), |
||
| 77 | 'type' => 'relationship', |
||
| 78 | 'attribute' => 'name', |
||
| 79 | ], |
||
| 80 | [ |
||
| 81 | // RESULT |
||
| 82 | 'label' => __('Result'), |
||
| 83 | 'type' => 'relationship', |
||
| 84 | 'name' => 'result', |
||
| 85 | 'attribute' => 'result_type', |
||
| 86 | 'model' => Result::class, |
||
| 87 | ], |
||
| 88 | ]); |
||
| 89 | |||
| 90 | CRUD::addFilter( |
||
| 91 | [ |
||
| 92 | 'type' => 'simple', |
||
| 93 | 'name' => 'noresult', |
||
| 94 | 'label' => __('No Result'), |
||
| 95 | ], |
||
| 96 | false, |
||
| 97 | function () { |
||
| 98 | CRUD::addClause('noResult'); |
||
| 99 | } |
||
| 100 | ); |
||
| 101 | |||
| 102 | CRUD::addFilter( |
||
| 103 | [ |
||
| 104 | 'type' => 'simple', |
||
| 105 | 'name' => 'hideparents', |
||
| 106 | 'label' => __('Hide Parents'), |
||
| 107 | ], |
||
| 108 | false, |
||
| 109 | function () { |
||
| 110 | CRUD::addClause('real'); |
||
| 111 | } |
||
| 112 | ); |
||
| 113 | |||
| 114 | CRUD::addFilter([ |
||
| 115 | 'name' => 'period_id', |
||
| 116 | 'type' => 'select2', |
||
| 117 | 'label' => __('Period'), |
||
| 118 | ], fn () => Period::all()->pluck('name', 'id')->toArray(), function ($value) { |
||
| 119 | CRUD::addClause('period', $value); |
||
| 120 | }); |
||
| 121 | |||
| 122 | CRUD::addFilter([ // select2_multiple filter |
||
| 123 | 'name' => 'result', |
||
| 124 | 'type' => 'select2', |
||
| 125 | 'label' => __('Result'), |
||
| 126 | ], fn () => ResultType::all()->pluck('name', 'id')->toArray(), function ($value) { |
||
| 127 | $this->crud->query = $this->crud->query->whereHas('result', function ($query) use ($value) { |
||
| 128 | $query->where('result_type_id', $value); |
||
| 129 | }); |
||
| 157 |