Conditions | 12 |
Paths | 60 |
Total Lines | 54 |
Code Lines | 39 |
Lines | 10 |
Ratio | 18.52 % |
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 |
||
87 | static function request($cart) { |
||
88 | $config = self::config(); |
||
89 | $sessionId = \Cache::get('PickPointSession', [ |
||
90 | 'Login' => $config['login'], |
||
91 | 'Password' => $config['pass'], |
||
92 | ], function ($data) { |
||
93 | $result = self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/login', $data); |
||
94 | return json_decode($result, true)['SessionId']; |
||
95 | }, 12 * 60 * 60); |
||
96 | $toId = ''; |
||
97 | View Code Duplication | foreach ($cart->delivery->fields as $field) { |
|
98 | if ($field->code === 'pickpoint') { |
||
99 | if (!empty($_POST['deliveryFields'][$field->id]) && is_string($_POST['deliveryFields'][$field->id])) { |
||
100 | $toId = $_POST['deliveryFields'][$field->id]; |
||
101 | } elseif (isset($cart->deliveryInfos[$field->id])) { |
||
102 | $toId = $cart->deliveryInfos[$field->id]->value; |
||
103 | } |
||
104 | break; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | if (!$toId) { |
||
109 | $fieldInfo = \Ecommerce\UserAdds\Field::get('deliveryfield_city', 'code'); |
||
110 | $field = \Ecommerce\Delivery\Field::get('city', 'code'); |
||
111 | if (isset($cart->infos[$fieldInfo->id])) { |
||
112 | $item = \Ecommerce\Delivery\Field\Item::get([['id', $cart->infos[$fieldInfo->id]->value], ['delivery_field_id', $field->id]]); |
||
113 | if ($item) { |
||
114 | $data = json_decode($item->data, true); |
||
115 | if (!empty($data['PostCodeList'])) { |
||
116 | $post = explode(',', $data['PostCodeList'])[0]; |
||
117 | $result = json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/postindexpostamatlist', ['PostIndex' => $post]), true); |
||
118 | if (!empty($result['PostamatList'][0]['CitiName'])) { |
||
119 | $toId = $result['PostamatList'][0]['Number']; |
||
120 | } |
||
121 | } |
||
122 | |||
123 | } |
||
124 | } |
||
125 | } |
||
126 | if (!$toId) { |
||
127 | return false; |
||
128 | } |
||
129 | |||
130 | $senderCity = 'Москва'; |
||
131 | |||
132 | return \Cache::get('pickPointCalc', [ |
||
133 | 'SessionId' => $sessionId, |
||
134 | 'IKN' => $config['ikn'], |
||
135 | 'FromCity' => $senderCity, |
||
136 | 'ToPT' => $toId, |
||
137 | ], function ($data) { |
||
138 | return json_decode(self::curl_get_file_contents('https://e-solution.pickpoint.ru/api/getzone', $data), true); |
||
139 | }); |
||
140 | } |
||
141 | |||
170 | } |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.