| Conditions | 2 |
| Paths | 18 |
| Total Lines | 63 |
| Code Lines | 44 |
| 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 |
||
| 64 | public function store(Request $request) |
||
| 65 | { |
||
| 66 | // unique values check |
||
| 67 | $this->validate($request, ['email' => 'unique:mst_enquiries,email', |
||
| 68 | 'contact' => 'unique:mst_enquiries,contact']); |
||
| 69 | |||
| 70 | // Start Transaction |
||
| 71 | DB::beginTransaction(); |
||
| 72 | |||
| 73 | try { |
||
| 74 | // store enquiries details |
||
| 75 | $enquiryData = array('name'=>$request->name, |
||
| 76 | 'DOB'=> $request->DOB, |
||
| 77 | 'gender'=> $request->gender, |
||
| 78 | 'contact'=> $request->contact, |
||
| 79 | 'email'=> $request->email, |
||
| 80 | 'address'=> $request->address, |
||
| 81 | 'status'=> \constEnquiryStatus::Lead , |
||
| 82 | 'pin_code'=> $request->pin_code , |
||
| 83 | 'occupation'=> $request->occupation , |
||
| 84 | 'start_by'=> $request->start_by , |
||
| 85 | 'interested_in'=> implode(',',$request->interested_in), |
||
| 86 | 'aim'=> $request->aim , |
||
| 87 | 'source'=> $request->source); |
||
| 88 | |||
| 89 | $enquiry = new Enquiry($enquiryData); |
||
| 90 | $enquiry->createdBy()->associate(Auth::user()); |
||
| 91 | $enquiry->updatedBy()->associate(Auth::user()); |
||
| 92 | $enquiry->save(); |
||
| 93 | |||
| 94 | //Store the followup details |
||
| 95 | $followupData = array('enquiry_id'=>$enquiry->id, |
||
| 96 | 'followup_by'=>$request->followup_by, |
||
| 97 | 'due_date'=>$request->due_date, |
||
| 98 | 'status'=> \constFollowUpStatus::Pending, |
||
| 99 | 'outcome'=>''); |
||
| 100 | |||
| 101 | $followup = new Followup($followupData); |
||
| 102 | $followup->createdBy()->associate(Auth::user()); |
||
| 103 | $followup->updatedBy()->associate(Auth::user()); |
||
| 104 | $followup->save(); |
||
| 105 | |||
| 106 | // SMS Trigger |
||
| 107 | $gym_name = \Utilities::getSetting('gym_name'); |
||
| 108 | $sender_id = \Utilities::getSetting('sms_sender_id'); |
||
| 109 | |||
| 110 | $sms_trigger = Sms_trigger::where('alias','=','enquiry_placement')->first(); |
||
| 111 | $message = $sms_trigger->message; |
||
| 112 | $sms_text = sprintf($message,$enquiry->name,$gym_name); |
||
| 113 | $sms_status = $sms_trigger->status; |
||
| 114 | |||
| 115 | \Utilities::Sms($sender_id,$enquiry->contact,$sms_text,$sms_status); |
||
| 116 | |||
| 117 | DB::commit(); |
||
| 118 | flash()->success('Enquiry was successfully created'); |
||
| 119 | return redirect (action('EnquiriesController@show', ['id' => $enquiry->id])); |
||
| 120 | } |
||
| 121 | |||
| 122 | catch (\Exception $e) |
||
| 123 | { |
||
| 124 | DB::rollback(); |
||
| 125 | flash()->error('Error while creating the Enquiry'); |
||
| 126 | return redirect (action('EnquiriesController@index')); |
||
| 127 | } |
||
| 187 | } |