Test Failed
Push — master ( 51d55d...1c8811 )
by Alexey
10:37 queued 05:27
created

DeliveryProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A calcPrice() 0 3 1
A deliveryTime() 0 6 1
A config() 0 8 2
A availablePayTypeGroups() 0 3 1
A getCity() 0 15 4
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;
12
13
14
class DeliveryProvider {
15
    static $name = 'Unnamed';
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
    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...
18
        return new \Money\Sums([]);
19
    }
20
21
    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...
22
        return [
23
            'min' => 0,
24
            'max' => 0
25
        ];
26
    }
27
28
    static function config() {
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...
29
        $provider = \Ecommerce\Delivery\Provider::get((new \ReflectionClass(get_called_class()))->getShortName(), 'object');
30
        $config = [];
31
        foreach ($provider->configs as $item) {
32
            $config[$item->name] = $item->value;
33
        }
34
        return $config;
35
    }
36
37
    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...
38
        return ['*'];
39
    }
40
41
    /**
42
     * @param \Ecommerce\Cart $cart
43
     * @return bool|\Ecommerce\Delivery\Field\Item
44
     */
45
    static function getCity($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...
46
        $fieldInfo = \Ecommerce\UserAdds\Field::get('deliveryfield_city', 'code');
47
        $field = \Ecommerce\Delivery\Field::get('city', 'code');
48
        $cityItem = null;
0 ignored issues
show
Unused Code introduced by
$cityItem is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
        if (isset($cart->infos[$fieldInfo->id])) {
50
            $itemId = $cart->infos[$fieldInfo->id]->value;
51
        }
52
        if (isset($cart->deliveryInfos[$field->id])) {
53
            $itemId = $cart->deliveryInfos[$field->id]->value;
54
        }
55
        if (!empty($itemId)) {
56
            return \Ecommerce\Delivery\Field\Item::get([['id', $itemId], ['delivery_field_id', $field->id]]);
57
        }
58
        return false;
59
    }
60
}