Conditions | 3 |
Paths | 2 |
Total Lines | 105 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
82 | public function setupListOperation() |
||
1 ignored issue
–
show
|
|||
83 | { |
||
84 | // Workaround for how the unique_translation validation |
||
85 | // works in App\Http\Requests\SkillCrudRequest. |
||
86 | $locale = 'en'; |
||
87 | if (null !== $this->request->input('locale')) { |
||
88 | $locale = $this->request->input('locale'); |
||
89 | } |
||
90 | App::setLocale($locale); |
||
91 | |||
92 | // Remove delete button. |
||
93 | $this->crud->removeButton('delete'); |
||
94 | |||
95 | // Add custom columns to the Skill index view. |
||
96 | $this->crud->addColumn([ |
||
97 | 'name' => 'id', |
||
98 | 'type' => 'text', |
||
99 | 'label' => 'ID', |
||
100 | 'orderable' => true |
||
101 | ]); |
||
102 | |||
103 | $this->crud->addColumn([ |
||
104 | 'name' => 'name', |
||
105 | 'type' => 'text', |
||
106 | 'label' => 'Name', |
||
107 | 'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { |
||
108 | $query->orWhere('name->' . $locale, 'like', "%$searchTerm%"); |
||
109 | }, |
||
110 | 'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
||
111 | return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
||
112 | } |
||
113 | ]); |
||
114 | |||
115 | $this->crud->addColumn([ |
||
116 | 'name' => 'description', |
||
117 | 'type' => 'text', |
||
118 | 'label' => 'Description', |
||
119 | 'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { |
||
120 | $query->orWhere('description->' . $locale, 'like', "%$searchTerm%"); |
||
121 | }, |
||
122 | 'orderable' => false, |
||
123 | ]); |
||
124 | |||
125 | $this->crud->addColumn([ |
||
126 | 'name' => 'skill_type.name', |
||
127 | 'key' => 'skill_type_name', |
||
128 | 'type' => 'text', |
||
129 | 'label' => 'Type', |
||
130 | 'orderable' => true, |
||
131 | 'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
||
132 | return $query->orderBy('skill_type_id', $columnDirection)->select('*'); |
||
133 | } |
||
134 | ]); |
||
135 | |||
136 | $this->crud->addColumn([ |
||
137 | 'label' => 'Classifications', |
||
138 | 'type' => 'select_multiple', |
||
139 | 'name' => 'classifications', |
||
140 | 'entity' => 'classifications', |
||
141 | 'attribute' => 'key', |
||
142 | 'model' => 'App\Models\Skill', |
||
143 | ]); |
||
144 | |||
145 | $this->crud->addColumn([ |
||
146 | 'name' => 'is_culture_skill', |
||
147 | 'label' => 'Culture', |
||
148 | 'type' => 'boolean', |
||
149 | 'orderable' => true, |
||
150 | ]); |
||
151 | |||
152 | $this->crud->addColumn([ |
||
153 | 'name' => 'is_future_skill', |
||
154 | 'label' => 'Future', |
||
155 | 'type' => 'boolean', |
||
156 | 'orderable' => true, |
||
157 | ]); |
||
158 | |||
159 | // Add select2_multiple filter for classifications. |
||
160 | $this->crud->addFilter([ |
||
161 | 'name' => 'classifications', |
||
162 | 'key' => 'classifications_filter', |
||
163 | 'type' => 'select2_multiple', |
||
164 | 'label' => 'Filter by classification' |
||
165 | ], function () { |
||
166 | // The options that show up in the select2. |
||
167 | return Classification::all()->pluck('key', 'id')->toArray(); |
||
168 | }, function ($values) { |
||
169 | // If the filter is active. |
||
170 | foreach (json_decode($values) as $key => $value) { |
||
171 | $this->crud->query = $this->crud->query->whereHas('classifications', function ($query) use ($value) { |
||
172 | $query->where('id', $value); |
||
173 | }); |
||
174 | } |
||
175 | }); |
||
176 | |||
177 | // Add filter for skills without classifications. |
||
178 | $this->crud->addFilter( |
||
179 | [ |
||
180 | 'type' => 'simple', |
||
181 | 'name' => 'noClassification', |
||
182 | 'label'=> 'No classification' |
||
183 | ], |
||
184 | false, |
||
185 | function () { |
||
186 | $this->crud->query = $this->crud->query->doesntHave('classifications'); |
||
187 | } |
||
201 |