Conditions | 3 |
Paths | 3 |
Total Lines | 52 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
112 | public function store(Request $request) |
||
113 | { |
||
114 | $checkoutRepo = new CheckoutRepository; |
||
115 | $orderStatusRepo = new OrderStatusRepository(new OrderStatus); |
||
116 | $os = $orderStatusRepo->findByName('Pedido Feito'); |
||
117 | |||
118 | $order = $checkoutRepo->buildCheckoutItems([ |
||
119 | 'reference' => Uuid::uuid4()->toString(), |
||
120 | 'courier_id' => 1, // @deprecated |
||
121 | 'customer_id' => $request->user()->id, |
||
122 | 'address_id' => $request->input('billing_address'), |
||
123 | 'order_status_id' => $os->id, |
||
124 | 'payment' => strtolower(config('pay-on-delivery.name')), |
||
125 | 'discounts' => 0, |
||
126 | 'total_products' => $this->cartRepo->getSubTotal(), |
||
127 | 'total' => $this->cartRepo->getTotal(2, $this->shippingFee), |
||
128 | 'total_shipping' => $this->shippingFee, |
||
129 | 'total_paid' => 0, |
||
130 | 'tax' => $this->cartRepo->getTax() |
||
131 | ]); |
||
132 | |||
133 | if (env('ACTIVATE_SHIPPING') == 1) { |
||
134 | $shipment = Shippo_Shipment::retrieve($this->shipmentObjId); |
||
135 | |||
136 | $details = [ |
||
137 | 'shipment' => [ |
||
138 | 'address_to' => json_decode($shipment->address_to, true), |
||
139 | 'address_from' => json_decode($shipment->address_from, true), |
||
140 | 'parcels' => [json_decode($shipment->parcels[0], true)] |
||
141 | ], |
||
142 | 'carrier_account' => $this->carrier->carrier_account, |
||
143 | 'servicelevel_token' => $this->carrier->servicelevel->token |
||
144 | ]; |
||
145 | |||
146 | $transaction = Shippo_Transaction::create($details); |
||
147 | |||
148 | if ($transaction['status'] != 'SUCCESS'){ |
||
149 | Log::error($transaction['messages']); |
||
150 | return redirect()->route('checkout.index')->with('error', 'There is an error in the shipment details. Check logs.'); |
||
151 | } |
||
152 | |||
153 | $orderRepo = new OrderRepository($order); |
||
154 | $orderRepo->updateOrder([ |
||
155 | 'courier' => $this->carrier->provider, |
||
156 | 'label_url' => $transaction['label_url'], |
||
157 | 'tracking_number' => $transaction['tracking_number'] |
||
158 | ]); |
||
159 | } |
||
160 | |||
161 | Cart::destroy(); |
||
162 | |||
163 | return redirect()->route('accounts', ['tab' => 'orders'])->with('message', 'Order successful!'); |
||
164 | } |
||
165 | } |