Conditions | 9 |
Paths | 27 |
Total Lines | 32 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | static function calcPrice($cart) { |
||
23 | |||
24 | $city = ''; |
||
25 | foreach ($cart->delivery->fields as $field) { |
||
26 | if ($field->code === 'index' && !empty($_POST['deliveryFields'][$field->id]) && is_string($_POST['deliveryFields'][$field->id])) { |
||
27 | $city = $_POST['deliveryFields'][$field->id]; |
||
28 | } |
||
29 | } |
||
30 | if (!$city) { |
||
31 | return new \Money\Sums([$cart->delivery->currency_id => 0]); |
||
32 | } |
||
33 | if (strpos($city, '66') === 0) { |
||
34 | $senderCity = '660000'; |
||
35 | } else { |
||
36 | $senderCity = '101000'; |
||
37 | } |
||
38 | $url = 'http://tariff.russianpost.ru/tariff/v1/calculate?json&'; |
||
39 | $data = [ |
||
40 | 'object' => 3020, |
||
41 | 'weight' => 2, |
||
42 | 'date' => date('Ymd'), |
||
43 | 'sumoc' => $cart->itemsSum()->sums[0], |
||
44 | 'from' => $senderCity, |
||
45 | 'to' => $city, |
||
46 | 'closed' => 1, |
||
47 | 'service' => 2, |
||
48 | 'isavia' => 0 |
||
49 | ]; |
||
50 | $result = json_decode(file_get_contents($url . http_build_query($data)), true); |
||
51 | $sum = !empty($result['tariff'][0]['ground']['valnds']) ? $result['tariff'][0]['ground']['valnds'] : (!empty($result['tariff'][0]['avia']['valnds']) ? $result['tariff'][0]['avia']['valnds'] : 0); |
||
52 | return new \Money\Sums([$cart->delivery->currency_id => $sum/100]); |
||
53 | } |
||
54 | } |
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.