Conditions | 2 |
Paths | 2 |
Total Lines | 75 |
Code Lines | 49 |
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 |
||
72 | public function setupListOperation() |
||
73 | { |
||
74 | // Required for order logic. |
||
75 | $locale = 'en'; |
||
76 | if (null !== $this->request->input('locale')) { |
||
77 | $locale = $this->request->input('locale'); |
||
78 | } |
||
79 | App::setLocale($locale); |
||
80 | |||
81 | // Remove delete button. |
||
82 | $this->crud->removeButton('delete'); |
||
83 | |||
84 | // Add custom columns to the Department index view. |
||
85 | $this->crud->addColumn([ |
||
86 | 'name' => 'id', |
||
87 | 'type' => 'text', |
||
88 | 'label' => 'ID', |
||
89 | 'orderable' => true, |
||
90 | ]); |
||
91 | |||
92 | $this->crud->addColumn([ |
||
93 | 'name' => 'name', |
||
94 | 'type' => 'text', |
||
95 | 'label' => 'Name', |
||
96 | 'orderable' => true, |
||
97 | 'limit' => 70, |
||
98 | 'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
||
99 | return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
||
100 | } |
||
101 | ]); |
||
102 | |||
103 | $this->crud->addColumn([ |
||
104 | 'name' => 'impact', |
||
105 | 'type' => 'text', |
||
106 | 'label' => 'Impact', |
||
107 | 'orderable' => false, |
||
108 | 'limit' => 70, |
||
109 | ]); |
||
110 | |||
111 | $this->crud->addColumn([ |
||
112 | 'name' => 'preference', |
||
113 | 'type' => 'text', |
||
114 | 'label' => 'Preference', |
||
115 | 'orderable' => false, |
||
116 | 'limit' => 70, |
||
117 | ]); |
||
118 | |||
119 | $this->crud->addColumn([ |
||
120 | 'name' => 'allow_indeterminate', |
||
121 | 'type' => 'check', |
||
122 | 'label' => 'Allow Indeterminate', |
||
123 | ]); |
||
124 | |||
125 | $this->crud->addColumn([ |
||
126 | 'name' => 'is_partner', |
||
127 | 'type' => 'check', |
||
128 | 'label' => 'Partner Department', |
||
129 | ]); |
||
130 | |||
131 | $this->crud->addColumn([ |
||
132 | 'name' => 'is_host', |
||
133 | 'type' => 'check', |
||
134 | 'label' => 'Talent Cloud Host', |
||
135 | ]); |
||
136 | |||
137 | // Add filter for departments that are partners |
||
138 | $this->crud->addFilter( |
||
139 | [ |
||
140 | 'type' => 'simple', |
||
141 | 'name' => 'partners', |
||
142 | 'label'=> 'Partner Departments' |
||
143 | ], |
||
144 | false, |
||
145 | function () { |
||
146 | $this->crud->addClause('where', 'is_partner', '=', true); |
||
147 | } |
||
168 |