| Conditions | 5 |
| Paths | 4 |
| Total Lines | 72 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 43 | protected function setupListOperation() |
||
| 44 | { |
||
| 45 | if (config('app.currency_position') === 'before') { |
||
| 46 | $currency = ['prefix' => config('app.currency_symbol')]; |
||
| 47 | } else { |
||
| 48 | $currency = ['suffix' => config('app.currency_symbol')]; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (config('invoicing.invoice_numbering') === 'manual') { |
||
| 52 | CRUD::column('receipt_number'); |
||
| 53 | } else { |
||
| 54 | CRUD::column('invoice_number'); |
||
| 55 | |||
| 56 | CRUD::addColumn([ |
||
| 57 | 'name' => 'invoiceType', |
||
| 58 | 'type' => 'relationship', |
||
| 59 | 'label' => __('Type'), |
||
| 60 | 'searchLogic' => false, |
||
| 61 | 'attribute' => 'name', |
||
| 62 | ]); |
||
| 63 | } |
||
| 64 | |||
| 65 | $this->crud->addColumn([ |
||
| 66 | 'name' => 'created_at', |
||
| 67 | 'key' => 'year', |
||
| 68 | 'label' => __('Year'), |
||
| 69 | 'type' => 'date', |
||
| 70 | 'format' => 'Y', |
||
| 71 | ]); |
||
| 72 | |||
| 73 | $this->crud->addColumn([ |
||
| 74 | 'name' => 'created_at', |
||
| 75 | 'key' => 'date', |
||
| 76 | 'label' => __('Date'), |
||
| 77 | 'type' => 'date', |
||
| 78 | ]); |
||
| 79 | |||
| 80 | CRUD::column('client_name')->label(__('Client name')); |
||
| 81 | CRUD::column('client_idnumber')->label(__('Client ID Number')); |
||
| 82 | CRUD::column('client_address')->label(__('Client address')); |
||
| 83 | CRUD::column('client_email')->label(__('Client email')); |
||
| 84 | $this->crud->addColumn( |
||
| 85 | array_merge([ |
||
| 86 | 'label' => __('Total price'), |
||
| 87 | 'type' => 'model_function', |
||
| 88 | 'function_name' => 'totalPrice', |
||
| 89 | ], $currency) |
||
| 90 | ); |
||
| 91 | |||
| 92 | $this->crud->addColumn( |
||
| 93 | array_merge([ |
||
| 94 | 'name' => 'balance', |
||
| 95 | 'label' => __('Remaining balance'), |
||
| 96 | 'type' => 'number', |
||
| 97 | ], $currency) |
||
| 98 | ); |
||
| 99 | |||
| 100 | CRUD::addFilter( |
||
| 101 | [ |
||
| 102 | 'type' => 'date_range', |
||
| 103 | 'name' => 'from_to', |
||
| 104 | 'label'=> __('Date range'), |
||
| 105 | ], |
||
| 106 | false, |
||
| 107 | function ($value) { // if the filter is active, apply these constraints |
||
| 108 | $dates = json_decode($value, null, 512, JSON_THROW_ON_ERROR); |
||
| 109 | |||
| 110 | if ($dates->from) { |
||
| 111 | CRUD::addClause('where', 'date', '>=', $dates->from); |
||
| 112 | } |
||
| 113 | if ($dates->to) { |
||
| 114 | CRUD::addClause('where', 'date', '<=', $dates->to.' 23:59:59'); |
||
| 115 | } |
||
| 162 |