| Conditions | 2 |
| Paths | 2 |
| Total Lines | 61 |
| Code Lines | 52 |
| 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 |
||
| 59 | public function goToCheckout(Request $r) |
||
| 60 | { |
||
| 61 | $r->validate([ |
||
| 62 | 'first_name' => 'required', |
||
| 63 | 'last_name' => 'required', |
||
| 64 | 'address' => 'required', |
||
| 65 | 'telephone' => 'required', |
||
| 66 | 'email_sped' => 'required', |
||
| 67 | 'floor' => 'required', |
||
| 68 | 'province' => 'required', |
||
| 69 | 'city' => 'required', |
||
| 70 | 'cap' => 'required', |
||
| 71 | ]); |
||
| 72 | |||
| 73 | |||
| 74 | $piva = $r->get('piva'); |
||
| 75 | $rag_soc = $r->get('rag_soc'); |
||
| 76 | $first_name = $r->get('first_name'); |
||
| 77 | $last_name = $r->get('last_name'); |
||
| 78 | $address = $r->get('address'); |
||
| 79 | $telephone = $r->get('telephone'); |
||
| 80 | $email_sped = $r->get('email_sped'); |
||
| 81 | $floor = $r->get('floor'); |
||
| 82 | $province = $r->get('province'); |
||
| 83 | $city = $r->get('city'); |
||
| 84 | $cap = $r->get('cap'); |
||
| 85 | |||
| 86 | $user = User::where('email',$email_sped)->first(); |
||
| 87 | //if user exist |
||
| 88 | if($user){ |
||
| 89 | $user->piva = $piva; |
||
| 90 | $user->company = $rag_soc; |
||
| 91 | $user->first_name = $first_name; |
||
| 92 | $user->last_name = $last_name; |
||
| 93 | $user->address = $address; |
||
| 94 | $user->telephone = $telephone; |
||
| 95 | $user->floor = $floor; |
||
| 96 | $user->province = $province; |
||
| 97 | $user->city = $city; |
||
| 98 | $user->cap = $cap; |
||
| 99 | $user->save(); |
||
| 100 | //if user doesn't exist |
||
| 101 | }else{ |
||
| 102 | $user = new User(); |
||
| 103 | $user->piva = $piva; |
||
| 104 | $user->company = $rag_soc; |
||
| 105 | $user->first_name = $first_name; |
||
| 106 | $user->last_name = $last_name; |
||
| 107 | $user->email = $email_sped; |
||
| 108 | $user->password = Hash::make('ciaociao'); |
||
| 109 | $user->address = $address; |
||
| 110 | $user->telephone = $telephone; |
||
| 111 | $user->floor = $floor; |
||
| 112 | $user->province = $province; |
||
| 113 | $user->city = $city; |
||
| 114 | $user->cap = $cap; |
||
| 115 | $user->save(); |
||
| 116 | Auth::login($user); |
||
| 117 | } |
||
| 118 | Template::MoveSessionToCart($user->id); |
||
| 119 | return response()->json(['link' => route('shop.checkout')]); |
||
| 120 | |||
| 123 |