Conditions | 18 |
Paths | 18710 |
Total Lines | 208 |
Code Lines | 150 |
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 |
||
143 | public function store(Request $request) |
||
144 | { |
||
145 | // Member Model Validation |
||
146 | $this->validate($request, ['email' => 'unique:mst_members,email', |
||
147 | 'contact' => 'unique:mst_members,contact', |
||
148 | 'member_code' => 'unique:mst_members,member_code', ]); |
||
149 | |||
150 | // Start Transaction |
||
151 | DB::beginTransaction(); |
||
152 | |||
153 | try { |
||
154 | // Store member's personal details |
||
155 | $memberData = ['name'=>$request->name, |
||
156 | 'DOB'=> $request->DOB, |
||
157 | 'gender'=> $request->gender, |
||
158 | 'contact'=> $request->contact, |
||
159 | 'emergency_contact'=> $request->emergency_contact, |
||
160 | 'health_issues'=> $request->health_issues, |
||
161 | 'email'=> $request->email, |
||
162 | 'address'=> $request->address, |
||
163 | 'member_id'=> $request->member_id, |
||
164 | 'proof_name'=> $request->proof_name, |
||
165 | 'member_code'=> $request->member_code, |
||
166 | 'status'=> $request->status, |
||
167 | 'pin_code'=> $request->pin_code, |
||
168 | 'occupation'=> $request->occupation, |
||
169 | 'aim'=> $request->aim, |
||
170 | 'source'=> $request->source, ]; |
||
171 | |||
172 | $member = new Member($memberData); |
||
173 | $member->createdBy()->associate(Auth::user()); |
||
174 | $member->updatedBy()->associate(Auth::user()); |
||
175 | $member->save(); |
||
176 | |||
177 | // Adding media i.e. Profile & proof photo |
||
178 | if ($request->hasFile('photo')) { |
||
179 | $member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.$request->photo->getClientOriginalExtension())->toCollection('profile'); |
||
180 | } |
||
181 | |||
182 | if ($request->hasFile('proof_photo')) { |
||
183 | $member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.$request->proof_photo->getClientOriginalExtension())->toCollection('proof'); |
||
184 | } |
||
185 | |||
186 | // Helper function for calculating payment status |
||
187 | $invoice_total = $request->admission_amount + $request->subscription_amount + $request->taxes_amount - $request->discount_amount; |
||
188 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
189 | $pending = $invoice_total - $request->payment_amount; |
||
190 | |||
191 | if ($request->mode == 1) { |
||
192 | if ($request->payment_amount == $invoice_total) { |
||
193 | $paymentStatus = \constPaymentStatus::Paid; |
||
194 | } elseif ($request->payment_amount > 0 && $request->payment_amount < $invoice_total) { |
||
195 | $paymentStatus = \constPaymentStatus::Partial; |
||
196 | } elseif ($request->payment_amount == 0) { |
||
197 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
198 | } else { |
||
199 | $paymentStatus = \constPaymentStatus::Overpaid; |
||
200 | } |
||
201 | } |
||
202 | |||
203 | // Storing Invoice |
||
204 | $invoiceData = ['invoice_number'=> $request->invoice_number, |
||
205 | 'member_id'=> $member->id, |
||
206 | 'total'=> $invoice_total, |
||
207 | 'status'=> $paymentStatus, |
||
208 | 'pending_amount'=> $pending, |
||
209 | 'discount_amount'=> $request->discount_amount, |
||
210 | 'discount_percent'=> $request->discount_percent, |
||
211 | 'discount_note'=> $request->discount_note, |
||
212 | 'tax'=> $request->taxes_amount, |
||
213 | 'additional_fees'=> $request->additional_fees, |
||
214 | 'note'=>' ', ]; |
||
215 | |||
216 | $invoice = new Invoice($invoiceData); |
||
217 | $invoice->createdBy()->associate(Auth::user()); |
||
218 | $invoice->updatedBy()->associate(Auth::user()); |
||
219 | $invoice->save(); |
||
220 | |||
221 | // Storing subscription |
||
222 | foreach ($request->plan as $plan) { |
||
223 | $subscriptionData = ['member_id'=> $member->id, |
||
224 | 'invoice_id'=> $invoice->id, |
||
225 | 'plan_id'=> $plan['id'], |
||
226 | 'start_date'=> $plan['start_date'], |
||
227 | 'end_date'=> $plan['end_date'], |
||
228 | 'status'=> \constSubscription::onGoing, |
||
229 | 'is_renewal'=>'0', ]; |
||
230 | |||
231 | $subscription = new Subscription($subscriptionData); |
||
232 | $subscription->createdBy()->associate(Auth::user()); |
||
233 | $subscription->updatedBy()->associate(Auth::user()); |
||
234 | $subscription->save(); |
||
235 | |||
236 | //Adding subscription to invoice(Invoice Details) |
||
237 | $detailsData = ['invoice_id'=> $invoice->id, |
||
238 | 'plan_id'=> $plan['id'], |
||
239 | 'item_amount'=> $plan['price'], ]; |
||
240 | |||
241 | $invoice_details = new Invoice_detail($detailsData); |
||
242 | $invoice_details->createdBy()->associate(Auth::user()); |
||
243 | $invoice_details->updatedBy()->associate(Auth::user()); |
||
244 | $invoice_details->save(); |
||
245 | } |
||
246 | |||
247 | // Store Payment Details |
||
248 | $paymentData = ['invoice_id'=> $invoice->id, |
||
249 | 'payment_amount'=> $request->payment_amount, |
||
250 | 'mode'=> $request->mode, |
||
251 | 'note'=> ' ', ]; |
||
252 | |||
253 | $payment_details = new Payment_detail($paymentData); |
||
254 | $payment_details->createdBy()->associate(Auth::user()); |
||
255 | $payment_details->updatedBy()->associate(Auth::user()); |
||
256 | $payment_details->save(); |
||
257 | |||
258 | if ($request->mode == 0) { |
||
259 | // Store Cheque Details |
||
260 | $chequeData = ['payment_id'=> $payment_details->id, |
||
261 | 'number'=> $request->number, |
||
262 | 'date'=> $request->date, |
||
263 | 'status'=> \constChequeStatus::Recieved, ]; |
||
264 | |||
265 | $cheque_details = new Cheque_detail($chequeData); |
||
266 | $cheque_details->createdBy()->associate(Auth::user()); |
||
267 | $cheque_details->updatedBy()->associate(Auth::user()); |
||
268 | $cheque_details->save(); |
||
269 | } |
||
270 | |||
271 | // On member transfer update enquiry Status |
||
272 | if ($request->has('transfer_id')) { |
||
273 | $enquiry = Enquiry::findOrFail($request->transfer_id); |
||
274 | $enquiry->status = \constEnquiryStatus::Member; |
||
275 | $enquiry->updatedBy()->associate(Auth::user()); |
||
276 | $enquiry->save(); |
||
277 | } |
||
278 | |||
279 | //Updating Numbering Counters |
||
280 | Setting::where('key', '=', 'invoice_last_number')->update(['value' => $request->invoiceCounter]); |
||
281 | Setting::where('key', '=', 'member_last_number')->update(['value' => $request->memberCounter]); |
||
282 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
283 | $gym_name = \Utilities::getSetting('gym_name'); |
||
284 | |||
285 | //SMS Trigger |
||
286 | if ($invoice->status == \constPaymentStatus::Paid) { |
||
287 | $sms_trigger = Sms_trigger::where('alias', '=', 'member_admission_with_paid_invoice')->first(); |
||
288 | $message = $sms_trigger->message; |
||
289 | $sms_text = sprintf($message, $member->name, $gym_name, $payment_details->payment_amount, $invoice->invoice_number); |
||
290 | $sms_status = $sms_trigger->status; |
||
291 | |||
292 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
293 | } elseif ($invoice->status == \constPaymentStatus::Partial) { |
||
294 | $sms_trigger = Sms_trigger::where('alias', '=', 'member_admission_with_partial_invoice')->first(); |
||
295 | $message = $sms_trigger->message; |
||
296 | $sms_text = sprintf($message, $member->name, $gym_name, $payment_details->payment_amount, $invoice->invoice_number, $invoice->pending_amount); |
||
297 | $sms_status = $sms_trigger->status; |
||
298 | |||
299 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
300 | } elseif ($invoice->status == \constPaymentStatus::Unpaid) { |
||
301 | if ($request->mode == 0) { |
||
302 | $sms_trigger = Sms_trigger::where('alias', '=', 'payment_with_cheque')->first(); |
||
303 | $message = $sms_trigger->message; |
||
304 | $sms_text = sprintf($message, $member->name, $payment_details->payment_amount, $cheque_details->number, $invoice->invoice_number, $gym_name); |
||
305 | $sms_status = $sms_trigger->status; |
||
306 | |||
307 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
308 | } else { |
||
309 | $sms_trigger = Sms_trigger::where('alias', '=', 'member_admission_with_unpaid_invoice')->first(); |
||
310 | $message = $sms_trigger->message; |
||
311 | $sms_text = sprintf($message, $member->name, $gym_name, $invoice->pending_amount, $invoice->invoice_number); |
||
312 | $sms_status = $sms_trigger->status; |
||
313 | |||
314 | \Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status); |
||
315 | } |
||
316 | } |
||
317 | |||
318 | if ($subscription->start_date < $member->created_at) { |
||
319 | $member->created_at = $subscription->start_date; |
||
320 | $member->updated_at = $subscription->start_date; |
||
321 | $member->save(); |
||
322 | |||
323 | $invoice->created_at = $subscription->start_date; |
||
324 | $invoice->updated_at = $subscription->start_date; |
||
325 | $invoice->save(); |
||
326 | |||
327 | foreach ($invoice->invoice_details as $invoice_detail) { |
||
328 | $invoice_detail->created_at = $subscription->start_date; |
||
329 | $invoice_detail->updated_at = $subscription->start_date; |
||
330 | $invoice_detail->save(); |
||
331 | } |
||
332 | |||
333 | $payment_details->created_at = $subscription->start_date; |
||
334 | $payment_details->updated_at = $subscription->start_date; |
||
335 | $payment_details->save(); |
||
336 | |||
337 | $subscription->created_at = $subscription->start_date; |
||
338 | $subscription->updated_at = $subscription->start_date; |
||
339 | $subscription->save(); |
||
340 | } |
||
341 | |||
342 | DB::commit(); |
||
343 | flash()->success('Member was successfully created'); |
||
344 | |||
345 | return redirect(action('MembersController@show', ['id' => $member->id])); |
||
346 | } catch (\Exception $e) { |
||
347 | DB::rollback(); |
||
348 | flash()->error('Error while creating the member'); |
||
349 | |||
350 | return redirect(action('MembersController@index')); |
||
351 | } |
||
471 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths