| Conditions | 3 |
| Paths | 4 |
| Total Lines | 60 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 42 | public function bill(ScheduledPayment $scheduledPayment) |
||
| 43 | { |
||
| 44 | // otherwise create a new one. |
||
| 45 | Log::info('User # '.backpack_user()->id.' is generating a invoice for a scheduled payment'); |
||
| 46 | |||
| 47 | // build an array with products to include |
||
| 48 | $products = []; |
||
| 49 | |||
| 50 | $enrollment = $scheduledPayment->enrollment; |
||
| 51 | |||
| 52 | array_push($products, [ |
||
| 53 | 'name' => $enrollment->name, |
||
| 54 | 'product_code' => $enrollment->product_code, |
||
| 55 | 'type' => 'scheduledPayment', |
||
| 56 | 'price' => $scheduledPayment->value, |
||
| 57 | 'quantity' => 1, |
||
| 58 | 'id' => $scheduledPayment->id, |
||
| 59 | ]); |
||
| 60 | |||
| 61 | // build an array with all contact data |
||
| 62 | $clients = []; |
||
| 63 | |||
| 64 | array_push($clients, [ |
||
| 65 | 'name' => $enrollment->student_name, |
||
| 66 | 'email' => $enrollment->student_email, |
||
| 67 | 'idnumber' => $enrollment->student->idnumber, |
||
| 68 | 'address' => $enrollment->student->address, |
||
| 69 | 'phone' => $enrollment->student->phone, |
||
| 70 | ]); |
||
| 71 | |||
| 72 | foreach ($enrollment->student->contacts as $client) { |
||
| 73 | array_push($clients, $client); |
||
| 74 | } |
||
| 75 | |||
| 76 | $data = [ |
||
| 77 | 'enrollment' => $enrollment, |
||
| 78 | 'products' => $products, |
||
| 79 | 'invoicetypes' => InvoiceType::all(), |
||
| 80 | 'clients' => $clients, |
||
| 81 | 'availableBooks' => Book::all(), |
||
| 82 | 'availableFees' => Fee::all(), |
||
| 83 | 'availableDiscounts' => Discount::all(), |
||
| 84 | 'availablePaymentMethods' => Paymentmethod::all(), |
||
| 85 | 'availableTaxes' => Tax::all(), |
||
| 86 | ]; |
||
| 87 | if (config('invoicing.price_categories_enabled')) { |
||
| 88 | $data = array_merge( |
||
| 89 | $data, |
||
| 90 | [ |
||
| 91 | 'priceCategories' => collect([ |
||
| 92 | 'price_a' => $enrollment->course->price, |
||
| 93 | 'price_b' => $enrollment->course->price_b, |
||
| 94 | 'price_c' => $enrollment->course->price_c, |
||
| 95 | ]), |
||
| 96 | 'studentPriceCategory' => $enrollment->student?->price_category, |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 101 | return view('carts.show', $data); |
||
| 102 | } |
||
| 104 |