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 — filters-dev ( c59b06...8ccd21 )
by Ivan
14:40 queued 04:15
created

PriceSliderRangeWidget   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 10
c 3
b 2
f 1
lcom 1
cbo 1
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()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

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