GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( b9b347...45f141 )
by Ivan
24s
created

PriceSliderRangeWidget   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 10
c 3
b 2
f 1
lcom 1
cbo 4
dl 0
loc 76
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C init() 0 61 10
1
<?php
2
namespace app\modules\shop\widgets;
3
4
use yii\db\Query;
5
use yii\helpers\ArrayHelper;
6
use Yii;
7
8
9
class PriceSliderRangeWidget extends SliderRangeWidget
10
{
11
12
    public $attributeName = 'Цена';
13
14
    public $minAttribute = 'price_min';
15
    public $maxAttribute = 'price_max';
16
    public $changeFlagAttribute = 'price_change_flag';
17
18
    public $categoryId;
19
20
21
    public function init()
22
    {
23
        $cacheKey = 'priceRangeCategory' . $this->categoryId;
24
25
        if (!$data = Yii::$app->cache->get($cacheKey)) {
26
            $dataMin = (new Query())->select([
27
                    'MIN(product.price / currency.convert_nominal * currency.convert_rate) AS min_price',
28
                    'product.currency_id AS min_currency',
29
                ])
30
                ->from(['product', 'product_category', 'currency'])
31
                ->where('product.id = product_category.object_model_id AND (product.currency_id = currency.id)')
32
                ->andWhere(
33
                    [
34
                        'product.active' => 1,
35
                        'product_category.category_id' => $this->categoryId
36
                    ]
37
                )->one();
38
39
            $dataMax = (new Query())->select([
40
                'MAX(product.price / currency.convert_nominal * currency.convert_rate) AS max_price',
41
                'product.currency_id AS max_currency',
42
            ])
43
                ->from(['product', 'product_category', 'currency'])
44
                ->where('product.id = product_category.object_model_id AND (product.currency_id = currency.id)')
45
                ->andWhere(
46
                        [
47
                            'product.active' => 1,
48
                            'product_category.category_id' => $this->categoryId
49
                        ]
50
                )->one();
51
52
            $data = ArrayHelper::merge($dataMax, $dataMin);
53
            if ($data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
54
                $data['min_price'] = (int) $data['min_price'];
55
                $data['max_price'] = (int) $data['max_price'];
56
                Yii::$app->cache->set($cacheKey, $data, 86400);
57
            }
58
59
        }
60
        if ($data && isset($data['min_price']) && isset($data['max_price'])) {
61
            $this->minValue = $data['min_price'];
62
            $this->maxValue = $data['max_price'];
63
            $get = ArrayHelper::merge(Yii::$app->request->get(), Yii::$app->request->post());
64
65
            if (isset($get[$this->minAttribute]) && is_numeric($get[$this->minAttribute])) {
66
                $this->changeFlagDefaultValue = 1;
67
                $this->minValueNow = $get[$this->minAttribute];
68
            } else {
69
                $this->minValueNow = $this->minValue;
70
            }
71
72
            if (isset($get[$this->maxAttribute]) && is_numeric($get[$this->maxAttribute])) {
73
                $this->changeFlagDefaultValue = 1;
74
                $this->maxValueNow = $get[$this->maxAttribute];
75
            } else {
76
                $this->maxValueNow = $this->maxValue;
77
            }
78
        }
79
        return parent::init();
80
81
    }
82
83
84
}