Test Failed
Push — master ( 2e584a...5aebc0 )
by Alexey
10:12
created

RussianPost   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 9
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
D calcPrice() 0 32 9
1
<?php
2
/**
3
 * INJI
4
 *
5
 * @author Alexey Krupskiy <[email protected]>
6
 * @link http://inji.ru/
7
 * @copyright 2017 Alexey Krupskiy
8
 * @license https://github.com/injitools/Inji/blob/master/LICENSE
9
 */
10
11
namespace Ecommerce\DeliveryProvider;
12
13
14
class RussianPost extends \Ecommerce\DeliveryProvider {
15
    static $name = 'PickPoint - курьерская служба';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
17
    /**
18
     * @param \Ecommerce\Cart $cart
19
     * @return \Money\Sums
20
     *
21
     */
22
    static function calcPrice($cart) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
}