Conditions | 2 |
Paths | 2 |
Total Lines | 106 |
Code Lines | 77 |
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 |
||
123 | protected function setupUpdateOperation() |
||
124 | { |
||
125 | CRUD::setValidation(InvoiceRequest::class); |
||
126 | |||
127 | CRUD::field('date')->label(__('Date'))->tab(__('Invoice')); |
||
128 | |||
129 | if (config('invoicing.invoice_numbering') === 'manual') { |
||
130 | CRUD::field('receipt_number')->tab(__('Invoice')); |
||
131 | } else { |
||
132 | CRUD::field('invoice_number')->tab(__('Invoice')); |
||
133 | |||
134 | CRUD::addField([ |
||
135 | 'name' => 'invoiceType', |
||
136 | 'type' => 'relationship', |
||
137 | 'label' => 'Type', |
||
138 | 'searchLogic' => false, |
||
139 | 'attribute' => 'name', |
||
140 | 'tab' => __('Invoice'), |
||
141 | ]); |
||
142 | } |
||
143 | |||
144 | CRUD::field('client_name')->label(__('Client name'))->tab(__('Invoice')); |
||
145 | CRUD::field('client_idnumber')->label(__('Client ID Number'))->tab(__('Invoice')); |
||
146 | CRUD::field('client_address')->label(__('Client address'))->tab(__('Invoice')); |
||
147 | CRUD::field('client_email')->label(__('Client email'))->tab(__('Invoice')); |
||
148 | |||
149 | CRUD::addField([ |
||
150 | 'tab' => __('Products'), |
||
151 | 'name' => 'alert', |
||
152 | 'type' => 'view', |
||
153 | 'view' => 'invoices/invoice-editing-alert', |
||
154 | ]); |
||
155 | |||
156 | CRUD::addField([ |
||
157 | 'name' => 'invoiceDetails', |
||
158 | 'label' => __('Products'), |
||
159 | 'type' => 'repeatable', |
||
160 | 'fields' => [ |
||
161 | [ |
||
162 | 'name' => 'id', |
||
163 | 'type' => 'hidden', |
||
164 | ], |
||
165 | [ |
||
166 | 'name' => 'product_name', |
||
167 | 'type' => 'text', |
||
168 | 'label' => __('Product'), |
||
169 | 'wrapper' => ['class' => 'form-group col-md-8'], |
||
170 | ], |
||
171 | [ |
||
172 | 'name' => 'quantity', |
||
173 | 'type' => 'number', |
||
174 | 'label' => __('Quantity'), |
||
175 | 'attributes' => ['step' => '0.01', 'min' => 1], |
||
176 | 'wrapper' => ['class' => 'form-group col-md-2'], |
||
177 | ], |
||
178 | array_merge([ |
||
179 | 'name' => 'price', |
||
180 | 'type' => 'number', |
||
181 | 'attributes' => ['step' => '0.01'], |
||
182 | 'label' => __('Price'), |
||
183 | 'wrapper' => ['class' => 'form-group col-md-2'], |
||
184 | ], $this->currency), |
||
185 | ], |
||
186 | 'tab' => __('Products'), |
||
187 | 'init_rows' => 0, |
||
188 | ]); |
||
189 | |||
190 | CRUD::addField([ |
||
191 | 'name' => 'payments', |
||
192 | 'label' => __('Payments'), |
||
193 | 'type' => 'repeatable', |
||
194 | 'fields' => [ |
||
195 | [ |
||
196 | 'name' => 'id', |
||
197 | 'type' => 'hidden', |
||
198 | ], |
||
199 | [ |
||
200 | 'name' => 'payment_method', |
||
201 | 'label' => __('Payment method'), |
||
202 | 'type' => 'select2_from_array', |
||
203 | 'options' => Paymentmethod::all()->pluck('name', 'code')->toArray(), |
||
204 | 'allows_null' => false, |
||
205 | 'wrapper' => ['class' => 'form-group col-md-6'], |
||
206 | ], |
||
207 | [ |
||
208 | 'name' => 'date', |
||
209 | 'type' => 'date', |
||
210 | 'label' => __('Date'), |
||
211 | 'wrapper' => ['class' => 'form-group col-md-3'], |
||
212 | ], |
||
213 | array_merge([ |
||
214 | 'name' => 'value', |
||
215 | 'type' => 'number', |
||
216 | 'attributes' => ['step' => '0.01'], |
||
217 | 'label' => __('Value'), |
||
218 | 'wrapper' => ['class' => 'form-group col-md-3'], |
||
219 | ], $this->currency), |
||
220 | [ |
||
221 | 'name' => 'comment', |
||
222 | 'type' => 'text', |
||
223 | 'label' => __('Comment'), |
||
224 | 'wrapper' => ['class' => 'form-group col-md-12'], |
||
225 | ], |
||
226 | ], |
||
227 | 'tab' => __('Payments'), |
||
228 | 'init_rows' => 0, |
||
229 | ]); |
||
312 |