Conditions | 7 |
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 |
||
127 | public function bill(Enrollment $enrollment) |
||
128 | { |
||
129 | Log::info('User # '.backpack_user()->id.' is generating a invoice'); |
||
130 | |||
131 | // build an array with products to include |
||
132 | $products = []; |
||
133 | |||
134 | foreach (Fee::where('default', 1)->get() as $fee) { |
||
135 | // Set quantity to 1 |
||
136 | |||
137 | array_push($products, $fee); |
||
138 | } |
||
139 | |||
140 | array_push($products, $enrollment); |
||
141 | |||
142 | if ($enrollment->course->books->count() > 0 && config('invoicing.add_books_to_invoices')) { |
||
143 | // Set quantity to 1 |
||
144 | |||
145 | foreach ($enrollment->course->books as $book) { |
||
146 | array_push($products, $book); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | // build an array with all contact data |
||
151 | $clients = []; |
||
152 | |||
153 | array_push($clients, [ |
||
154 | 'name' => $enrollment->student_name, |
||
155 | 'email' => $enrollment->student_email, |
||
156 | 'idnumber' => $enrollment->student->idnumber, |
||
157 | 'address' => $enrollment->student->address, |
||
158 | 'phone' => $enrollment->student->phone, |
||
159 | ]); |
||
160 | |||
161 | foreach ($enrollment->student->contacts as $client) { |
||
162 | array_push($clients, $client); |
||
163 | } |
||
164 | |||
165 | $data = [ |
||
166 | 'enrollment' => $enrollment, |
||
167 | 'products' => $products, |
||
168 | 'invoicetypes' => InvoiceType::all(), |
||
169 | 'clients' => $clients, |
||
170 | 'availableBooks' => Book::all(), |
||
171 | 'availableFees' => Fee::all(), |
||
172 | 'availableDiscounts' => Discount::all(), |
||
173 | 'availablePaymentMethods' => Paymentmethod::all(), |
||
174 | 'availableTaxes' => Tax::all(), |
||
175 | ]; |
||
176 | |||
177 | if (config('invoicing.price_categories_enabled')) { |
||
178 | $data = array_merge($data, |
||
179 | [ |
||
180 | 'priceCategories' => collect([ |
||
181 | 'price_a' => $enrollment->course->price, |
||
182 | 'price_b' => $enrollment->course->price_b, |
||
183 | 'price_c' => $enrollment->course->price_c, |
||
184 | ]), |
||
185 | 'studentPriceCategory' => $enrollment->student?->price_category, |
||
186 | ] |
||
187 | ); |
||
188 | } |
||
189 | |||
190 | return view('carts.show', $data); |
||
191 | } |
||
221 |