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 ( 2d5011...ba6635 )
by
unknown
10:06
created

SetCanonicalBehavior::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace app\modules\seo\behaviors;
4
5
use app\modules\shop\models\Product;
6
use yii\base\Controller;
7
use yii\base\Behavior;
8
use yii\helpers\Url;
9
use Yii;
10
11
class SetCanonicalBehavior extends Behavior
12
{
13
    public $labels = [
14
        'gclid',
15
        'utm_medium',
16
        'utm_source',
17
        'utm_campaign',
18
        'utm_content',
19
        'utm_term',
20
        '_openstat'
21
    ];
22
23
    public function events()
24
    {
25
        return [
26
            Controller::EVENT_BEFORE_ACTION => 'setCanonical',
27
        ];
28
    }
29
30
    public function setCanonical()
31
    {
32
        $get = Yii::$app->request->get();
33
        $setCanonical = false;
34
35
        foreach ($this->labels as $label) {
36
            if (array_key_exists($label, $get)) {
37
                unset($get[$label]);
38
                $setCanonical = true;
39
            }
40
        }
41
42
        if ($setCanonical) {
43
            $get[0] = '/' . Yii::$app->controller->getRoute();
44
            if ('/' . Yii::$app->requestedAction->controller->route === Yii::getAlias('@product')) {
45
                $get['model'] = Product::findById(Yii::$app->request->get('model_id'));
46
                unset($get['model_id']);
47
            }
48
            $this->owner->view->registerLinkTag(
49
                [
50
                    'rel' => 'canonical',
51
                    'href' => Url::toRoute($get, true)
52
                ]
53
            );
54
55
        }
56
    }
57
}
58