Conditions | 22 |
Paths | 38 |
Total Lines | 47 |
Code Lines | 31 |
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 |
||
28 | public function parseOrders($orders) { |
||
29 | foreach ($orders as $order) { |
||
30 | |||
31 | $cart = \Ecommerce\Cart::get((string) $order->Номер); |
||
32 | |||
33 | if (!$cart) { |
||
34 | continue; |
||
35 | } |
||
36 | |||
37 | $reqs = []; |
||
38 | |||
39 | foreach ($order->ЗначенияРеквизитов->ЗначениеРеквизита as $req) { |
||
40 | $reqs[(string) $req->Наименование] = (string) $req->Значение; |
||
41 | } |
||
42 | |||
43 | $payed = false; |
||
44 | $cancel = false; |
||
45 | |||
46 | if (!empty($reqs['Дата оплаты по 1С']) && $reqs['Дата оплаты по 1С'] != 'T') { |
||
47 | $payed = true; |
||
48 | $date = new \DateTime((string) $reqs['Дата оплаты по 1С']); |
||
49 | $cart->payed_date = $date->format('Y-m-d H:i:s'); |
||
50 | } elseif ( |
||
51 | (!empty($reqs['Отменен']) && $reqs['Отменен'] == 'true') || |
||
52 | (!empty($reqs['Дата оплаты по 1С']) && $reqs['Дата оплаты по 1С'] == 'T')) { |
||
53 | $cancel = true; |
||
54 | } |
||
55 | |||
56 | $this->updateCartItems($cart, $order->Товары->Товар); |
||
57 | $cart->payed = $payed; |
||
58 | if ($payed && $cart->cart_status_id == 3) { |
||
59 | $cart->cart_status_id = 5; |
||
60 | $cart->save(); |
||
61 | } elseif ($cancel && $cart->cart_status_id == 3) { |
||
62 | $cart->cart_status_id = 4; |
||
63 | } |
||
64 | if ($cart->warehouse_block && !$payed && !$cancel && !empty($reqs['Проведен']) && $reqs['Проведен'] == 'true') { |
||
65 | $cart->warehouse_block = 0; |
||
66 | foreach ($cart->cartItems as $cci) { |
||
67 | if ($cci->price && $cci->price->offer) { |
||
68 | $cci->price->offer->changeWarehouse('-' . (float) $cci->count); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | $cart->save(); |
||
73 | } |
||
74 | } |
||
75 | |||
154 |