Test Failed
Push — master ( 1c8811...dcad06 )
by Alexey
07:10
created

RussianPost   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 3 Features 0
Metric Value
dl 0
loc 74
rs 10
c 6
b 3
f 0
wmc 16
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A calcPrice() 0 9 3
C request() 0 35 7
B deliveryTime() 0 20 5
A availablePayTypeGroups() 0 3 1
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
use Ecommerce\UserAdds\Field;
15
16
class RussianPost extends \Ecommerce\DeliveryProvider {
17
    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...
18
19
    static function request($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...
20
        $city = '';
21
        foreach ($cart->deliveryInfos as $deliveryInfo) {
22
            if ($deliveryInfo->field->code == 'index') {
23
                $city = $deliveryInfo->value;
24
            }
25
        }
26
        if (!$city) {
27
            $cityItem = static::getCity($cart);
28
            if ($cityItem) {
29
                $data = json_decode($cityItem->data, true);
30
                if (!empty($data['PostCodeList'])) {
31
                    $city = explode(',', $data['PostCodeList'])[0];
32
                }
33
            }
34
        }
35
        if (!$city) {
36
            return [];
37
        }
38
        $senderCity = '101000';
39
40
        $data = [
41
            'object' => 4030,
42
            'weight' => '3000',
43
            'date' => date('Ymd'),
44
            //'sumoc' => $cart->itemsSum()->sums[0],
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
            'from' => $senderCity,
46
            'to' => $city,
47
            'delivery' => 1,
48
        ];
49
        $result = \Cache::get('russianPostCalc', $data, function ($data) {
50
            return file_get_contents('http://tariff.russianpost.ru/tariff/v1/calculate?json&' . http_build_query($data));
51
        }, 4 * 60 * 60);
52
        return json_decode($result, true);
53
    }
54
55
    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...
56
        $result = static::request($cart);
57
        $curId = $cart->delivery ? $cart->delivery->currency_id : 0;
58
        if (empty($result['paynds'])) {
59
            return new \Money\Sums([$curId => 0]);
60
        }
61
        $sum = $result['paynds'];
62
        return new \Money\Sums([$curId => round($sum / 100 * 1.1, 2)]);
63
    }
64
65
    static function deliveryTime($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...
66
        $result = static::request($cart);
67
68
        if (!empty($result['delivery'])) {
69
            return $result['delivery'];
70
        }
71
        if (!empty($result['from']) && !empty($result['to'])) {
72
            $url = "http://postcalc.ru/web.php?Extended=1&Output=json&From={$result['from']}&Weight=3000&Valuation=0&Step=0&Date=22.11.2017&IBase=p&ProcessingFee=0&PackingFee=0&Round=0.01&VAT=1&To={$result['to']}";
73
            $result = \Cache::get('russianPostTimeCalc', $url, function ($data) {
74
                return file_get_contents($data);
75
            }, 4 * 60 * 60);
76
            $result = json_decode($result, true);
77
            if (!empty($result['ПростаяБандероль']['СрокДоставки'])) {
78
                return ['min' => $result['ПростаяБандероль']['СрокДоставки']];
79
            }
80
81
82
        }
83
        return ['min' => 0, 'max' => 0];
84
    }
85
86
    static function availablePayTypeGroups($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...
87
        return ['online'];
88
    }
89
}