Conditions | 6 |
Paths | 16 |
Total Lines | 64 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
117 | public function bill(Enrollment $enrollment) |
||
118 | { |
||
119 | Log::info('User # '.backpack_user()->id.' is generating a invoice'); |
||
120 | |||
121 | // build an array with products to include |
||
122 | $products = []; |
||
123 | |||
124 | foreach (Fee::where('default', 1)->get() as $fee) { |
||
125 | // Set quantity to 1 |
||
126 | |||
127 | array_push($products, $fee); |
||
128 | } |
||
129 | |||
130 | array_push($products, $enrollment); |
||
131 | |||
132 | if ($enrollment->course->books->count() > 0) { |
||
133 | // Set quantity to 1 |
||
134 | |||
135 | foreach ($enrollment->course->books as $book) { |
||
136 | array_push($products, $book); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | // build an array with all contact data |
||
141 | $clients = []; |
||
142 | |||
143 | array_push($clients, [ |
||
144 | 'name' => $enrollment->student_name, |
||
145 | 'email' => $enrollment->student_email, |
||
146 | 'idnumber' => $enrollment->student->idnumber, |
||
147 | 'address' => $enrollment->student->address, |
||
148 | 'phone' => $enrollment->student->phone, |
||
149 | ]); |
||
150 | |||
151 | foreach ($enrollment->student->contacts as $client) { |
||
152 | array_push($clients, $client); |
||
153 | } |
||
154 | |||
155 | $data = [ |
||
156 | 'enrollment' => $enrollment, |
||
157 | 'products' => $products, |
||
158 | 'invoicetypes' => InvoiceType::all(), |
||
159 | 'clients' => $clients, |
||
160 | 'availableBooks' => Book::all(), |
||
161 | 'availableFees' => Fee::all(), |
||
162 | 'availableDiscounts' => Discount::all(), |
||
163 | 'availablePaymentMethods' => Paymentmethod::all(), |
||
164 | 'availableTaxes' => Tax::all(), |
||
165 | ]; |
||
166 | |||
167 | if (config('invoicing.price_categories_enabled')) { |
||
168 | $data = array_merge($data, |
||
169 | [ |
||
170 | 'priceCategories' => collect([ |
||
171 | 'priceA' => $enrollment->course->price, |
||
172 | 'priceB' => $enrollment->course->price_b, |
||
173 | 'priceC' => $enrollment->course->price_c, |
||
174 | ]), |
||
175 | 'studentPriceCategory' => $enrollment->student?->price_category, |
||
176 | ] |
||
177 | ); |
||
178 | } |
||
179 | |||
180 | return view('carts.show', $data); |
||
181 | } |
||
211 |