Test Failed
Push — master ( 5878a7...1a655d )
by Alexey
05:08
created

CDEK::availablePayTypeGroups()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
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
use Ecommerce\Delivery\Field\Item;
14
use Ecommerce\UserAdds\Field;
15
16
class CDEK extends \Ecommerce\DeliveryProvider {
17
    static $name = 'СДЭК - курьерская служба';
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
    /**
20
     * @param \Ecommerce\Cart $cart
21
     */
22
    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...
23
        $cityId = 0;
24
        $senderCity = 44;
25
        $tariff = 136;
26
        $fieldInfo = Field::get('deliveryfield_city', 'code');
27
        $field = \Ecommerce\Delivery\Field::get('city', 'code');
28 View Code Duplication
        if (isset($cart->infos[$fieldInfo->id])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
            $item = Item::get([['id', $cart->infos[$fieldInfo->id]->value], ['delivery_field_id', $field->id]]);
30
            if ($item) {
31
                $cityId = json_decode($item->data, true)['ID'];
32
            }
33
        }
34
        $field = \Ecommerce\Delivery\Field::get('cdektype', 'code');
35 View Code Duplication
        if (isset($cart->deliveryInfos[$field->id])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
            $item = Item::get([['id', $cart->deliveryInfos[$field->id]->value], ['delivery_field_id', $field->id]]);
37
            if ($item) {
38
                $tariff = $item->data;
39
            }
40
        }
41
        if ($cityId) {
42
            $config = self::config();
43
            return \Cache::get('pickPointCalc', [
44
                'login' => $config['authLogin'],
45
                'pass' => $config['authPassword'],
46
                'senderCity' => $senderCity,
47
                'cityId' => $cityId,
48
                'tariff' => $tariff,
49
            ], function ($data) {
50
                $calc = new \Ecommerce\Vendor\CalculatePriceDeliveryCdek();
51
                $calc->setAuth($data['login'], $data['pass']);
52
                $calc->setDateExecute(date('Y-m-d H:i:s'));
53
                $calc->setSenderCityId($data['senderCity']);
54
                //устанавливаем город-получатель
55
                $calc->setReceiverCityId($data['cityId']);
56
                $calc->setTariffId($data['tariff']);
57
                $calc->addGoodsItemBySize(3, 25, 25, 24);
58
                if ($calc->calculate()) {
59
                    return $calc->getResult();
60
                } else {
61
                    //var_dump($tariff,$calc->getError());
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% 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...
62
                    return false;
63
                }
64
            });
65
        }
66
        return false;
67
    }
68
69
    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...
70
        $result = self::request($cart);
71
        if (!empty($result['result']['price'])) {
72
            return new \Money\Sums([$cart->delivery->currency_id => round($result['result']['price'] * 1.1, 2)]);
73
        }
74
        return new \Money\Sums([$cart->delivery->currency_id => 0]);
75
    }
76
77
    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...
78
        $result = self::request($cart);
79
        if (isset($result['result']['deliveryPeriodMin'])) {
80
            return [
81
                'min' => $result['result']['deliveryPeriodMin'],
82
                'max' => $result['result']['deliveryPeriodMax'],
83
            ];
84
        }
85
        return [
86
            'min' => 0,
87
            'max' => 0,
88
        ];
89
    }
90
91
    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...
92
        $field = \Ecommerce\Delivery\Field::get('cdektype', 'code');
93
        if (isset($cart->deliveryInfos[$field->id])) {
94
            $item = Item::get([['id', $cart->deliveryInfos[$field->id]->value], ['delivery_field_id', $field->id]]);
95
            if ($item) {
96
                if ($item->data == 137) {
97
                    return ['*'];
98
                }
99
            }
100
        }
101
        return ['online'];
102
    }
103
}