| Conditions | 4 |
| Paths | 2 |
| Total Lines | 75 |
| Code Lines | 56 |
| 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 |
||
| 32 | public function setupListOperation() |
||
|
1 ignored issue
–
show
|
|||
| 33 | { |
||
| 34 | // Required for order logic. |
||
| 35 | $locale = 'en'; |
||
| 36 | if (null !== $this->request->input('locale')) { |
||
| 37 | $locale = $this->request->input('locale'); |
||
| 38 | } |
||
| 39 | App::setLocale($locale); |
||
| 40 | |||
| 41 | // Add the custom blade buttons found in resources/views/vendor/backpack/crud/buttons/. |
||
| 42 | $this->crud->addButtonFromView('line', 'job_admin_edit', 'job_admin_edit', 'end'); |
||
| 43 | $this->crud->addButtonFromView('line', 'spb_link', 'spb_link', 'end'); |
||
| 44 | $this->crud->addButtonFromView('line', 'jpb_link', 'jpb_link', 'end'); |
||
| 45 | $this->crud->addButtonFromView('line', 'job_poster_link', 'job_poster_link', 'end'); |
||
| 46 | |||
| 47 | |||
| 48 | $this->crud->addColumn([ |
||
| 49 | 'name' => 'id', |
||
| 50 | 'type' => 'number', |
||
| 51 | 'label' => 'ID' |
||
| 52 | ]); |
||
| 53 | $this->crud->addColumn([ |
||
| 54 | 'name' => 'title', |
||
| 55 | 'type' => 'text', |
||
| 56 | 'label' => 'Title', |
||
| 57 | 'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
||
| 58 | return $query->orderBy('title->' . $locale, $columnDirection)->select('*'); |
||
| 59 | } |
||
| 60 | ]); |
||
| 61 | $this->crud->addColumn([ |
||
| 62 | 'name' => 'status', |
||
| 63 | 'label' => 'Status', |
||
| 64 | 'type' => 'model_function', |
||
| 65 | 'function_name' => 'status' |
||
| 66 | ]); |
||
| 67 | $this->crud->addColumn([ |
||
| 68 | 'name' => 'published', |
||
| 69 | 'label' => 'Published', |
||
| 70 | 'type' => 'check', |
||
| 71 | ]); |
||
| 72 | $this->crud->addColumn([ |
||
| 73 | 'name' => 'manager_user_name', |
||
| 74 | 'type' => 'closure', |
||
| 75 | 'label' => 'Manager', |
||
| 76 | 'orderable' => false, |
||
| 77 | 'function' => function ($entry) { |
||
| 78 | return '<a href="' . route('manager.profile.edit', $entry->manager->user->id) . '" target="_blank">' . $entry->manager->user->full_name . '</a>'; |
||
| 79 | } |
||
| 80 | ]); |
||
| 81 | $this->crud->addColumn([ |
||
| 82 | 'name' => 'department.name', |
||
| 83 | 'label' => 'Department', |
||
| 84 | 'type' => 'text' |
||
| 85 | ]); |
||
| 86 | $this->crud->addColumn([ |
||
| 87 | 'name' => 'submitted_applications_count', |
||
| 88 | 'label' => 'Total Applications', |
||
| 89 | 'type' => 'model_function', |
||
| 90 | 'function_name' => 'submitted_applications_count' |
||
| 91 | ]); |
||
| 92 | |||
| 93 | // Filters. |
||
| 94 | $this->crud->addFilter([ |
||
| 95 | 'name' => 'departments', |
||
| 96 | 'type' => 'select2_multiple', |
||
| 97 | 'label' => 'Departments' |
||
| 98 | ], function () { |
||
| 99 | return Department::all()->pluck('name', 'id')->toArray(); |
||
| 100 | }, function ($values) { |
||
| 101 | $this->crud->addClause('WhereHas', 'department', function ($query) use ($values) { |
||
| 102 | foreach (json_decode($values) as $key => $value) { |
||
| 103 | if ($key === 0) { |
||
| 104 | $query->where('id', $value); |
||
| 105 | } else { |
||
| 106 | $query->orWhere('id', $value); |
||
| 107 | } |
||
| 215 |