Conditions | 10 |
Paths | 2 |
Total Lines | 67 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 namespace App\Http\Controllers\Backend; |
||
34 | public function index($clientId) |
||
35 | { |
||
36 | $client = $this->client->find($clientId); |
||
37 | if ($this->request->wantsJson()) { |
||
38 | |||
39 | $order = $this->order->getModel()->select( |
||
40 | ['id', 'created_at', 'generated_custom_order_id', 'order_status_id', 'client_id', 'delivery_order_address_id', 'bill_order_address_id', |
||
41 | 'price_with_tax'] |
||
42 | )->with(array('orderStatus', 'orderPaymentMethod', 'orderSendingMethod', 'products', 'client', 'orderBillAddress', 'orderDeliveryAddress'))->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id)->where('client_id', '=', $clientId); |
||
43 | |||
44 | |||
45 | $datatables = DataTables::of($order) |
||
46 | |||
47 | ->addColumn('status', function ($order) { |
||
48 | if ($order->orderStatus) { |
||
49 | return $order->orderStatus->title; |
||
50 | } |
||
51 | }) |
||
52 | |||
53 | ->addColumn('created_at', function ($order) { |
||
54 | return date('d F H:i', strtotime($order->created_at)); |
||
55 | }) |
||
56 | ->addColumn('status', function ($order) { |
||
57 | if ($order->orderStatus) { |
||
58 | if ($order->orderStatus->color) { |
||
59 | return '<a href="/admin/order/'.$order->id.'" style="text-decoration:none;"><span style="background-color:'.$order->orderStatus->color.'; padding: 10px; line-height:30px; text-align:center; color:white;">'.$order->orderStatus->title.'</span></a>'; |
||
60 | } |
||
61 | return $order->orderStatus->title; |
||
62 | } |
||
63 | }) |
||
64 | ->addColumn('client', function ($order) { |
||
65 | if ($order->client) { |
||
66 | if ($order->orderBillAddress) { |
||
67 | return $order->orderBillAddress->firstname.' '.$order->orderBillAddress->lastname; |
||
68 | } |
||
69 | } |
||
70 | }) |
||
71 | ->addColumn('products', function ($order) { |
||
72 | if ($order->products) { |
||
73 | return $order->products->count(); |
||
74 | } |
||
75 | }) |
||
76 | ->addColumn('price_with_tax', function ($order) { |
||
77 | $money = '€ '.$order->getPriceWithTaxNumberFormat(); |
||
78 | return $money; |
||
79 | }) |
||
80 | ->addColumn('paymentMethod', function ($order) { |
||
81 | if ($order->orderPaymentMethod) { |
||
82 | return $order->orderPaymentMethod->title; |
||
83 | } |
||
84 | }) |
||
85 | ->addColumn('sendingMethod', function ($order) { |
||
86 | if ($order->orderSendingMethod) { |
||
87 | return $order->orderSendingMethod->title; |
||
88 | } |
||
89 | }) |
||
90 | ->addColumn('action', function ($order) { |
||
91 | $download = '<a href="/admin/order/'.$order->id.'/download" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>Download</a> '; |
||
92 | $links = '<a href="/admin/order/'.$order->id.'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Show</a> '.$download; |
||
93 | |||
94 | return $links; |
||
95 | }); |
||
96 | |||
97 | return $datatables->rawColumns(['status', 'action'])->make(true); |
||
98 | } |
||
99 | |||
100 | return view('backend.client_order.index')->with(array('client' => $client)); |
||
101 | } |
||
102 | } |