Conditions | 2 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 42 |
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 |
||
28 | protected function setupListOperation() |
||
29 | { |
||
30 | $this->crud->addColumn([ |
||
31 | 'name' => 'id', |
||
32 | 'type' => 'number', |
||
33 | 'label' => 'ID', |
||
34 | 'orderable' => true, |
||
35 | ]); |
||
36 | |||
37 | $this->crud->addColumn([ |
||
38 | 'name' => 'job_poster.title', |
||
39 | 'type' => 'text', |
||
40 | 'label' => 'Job Poster Title', |
||
41 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
42 | $query->orWhereHas('job_poster', function ($q) use ($searchTerm) { |
||
43 | $q->where('title', 'ilike', '%'.$searchTerm.'%'); |
||
44 | }); |
||
45 | } |
||
46 | ]); |
||
47 | |||
48 | $this->crud->addColumn([ |
||
49 | 'name' => 'applicant.user.full_name', |
||
50 | 'type' => 'text', |
||
51 | 'label' => 'Applicant Name', |
||
52 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
53 | $query->orWhereHas('applicant.user', function ($q) use ($searchTerm) { |
||
54 | $q->where('first_name', 'ilike', '%'.$searchTerm.'%') |
||
55 | ->orWhere('last_name', 'ilike', '%'.$searchTerm.'%'); |
||
56 | }); |
||
57 | } |
||
58 | ]); |
||
59 | |||
60 | $this->crud->addColumn([ |
||
61 | 'name' => 'applicant.user.email', |
||
62 | 'type' => 'text', |
||
63 | 'label' => 'Applicant Email', |
||
64 | 'searchLogic' => function ($query, $column, $searchTerm) { |
||
65 | $query->orWhereHas('applicant.user', function ($q) use ($searchTerm) { |
||
66 | $q->where('email', 'ilike', '%'.$searchTerm.'%'); |
||
67 | }); |
||
68 | } |
||
69 | ]); |
||
70 | |||
71 | $this->crud->addColumn([ |
||
72 | 'name' => 'application_status.name', |
||
73 | 'type' => 'text', |
||
74 | 'label' => 'Application Status', |
||
75 | ]); |
||
76 | |||
77 | $this->crud->addFilter([ |
||
78 | 'name' => 'application_status', |
||
79 | 'key' => 'application_status_filter', |
||
80 | 'type' => 'select2_multiple', |
||
81 | 'label' => 'Filter by Application Status' |
||
82 | ], function () { |
||
83 | // The options that show up in the select2. |
||
84 | return ApplicationStatus::all()->pluck('name', 'id')->toArray(); |
||
85 | }, function ($values) { |
||
86 | // If the filter is active. |
||
87 | foreach (json_decode($values) as $key => $value) { |
||
88 | $this->crud->query = $this->crud->query->orWhereHas('application_status', function ($query) use ($value) { |
||
89 | $query->where('id', $value); |
||
90 | }); |
||
95 |