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
Pull Request — master (#301)
by
unknown
11:44
created

SetCanonicalBehavior::setCanonical()   C

Complexity

Conditions 7
Paths 20

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 6.7272
cc 7
eloc 18
nc 20
nop 0
1
<?php
2
3
namespace app\modules\core\behaviors;
4
5
use yii\base\Behavior;
6
use yii\base\Controller;
7
use Yii;
8
9
class SetCanonicalBehavior extends Behavior
10
{
11
    public $labels = [
12
        'gclid',
13
        'utm_medium',
14
        'utm_source',
15
        'utm_campaign',
16
        'utm_content',
17
        'utm_term',
18
        '_openstat'
19
    ];
20
21
    private $_canonical;
22
23
    public function events()
24
    {
25
        return [
26
            Controller::EVENT_BEFORE_ACTION => 'setCanonical',
27
        ];
28
    }
29
30
    public function setCanonical()
31
    {
32
        $request = Yii::$app->request;
33
        $setCanonical = false;
34
        $queryParams = !empty($request->queryParams) ? $request->queryParams : [];
35
        $this->_canonical = $request->absoluteUrl;
36
37
        foreach ($this->labels as $label) {
38
            foreach ($queryParams as $key => $value) {
39
                if ($key == $label) {
40
                    if (false == empty($value)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
41
                        $rm = $key .'='. $value;
42
                    } else {
43
                        $rm = $key;
44
                    }
45
                    $this->_canonical = str_replace(['?'.$rm.'&', '?'.$rm, '&'.$rm], ['?','',''], $this->_canonical);
46
                    $setCanonical = true;
47
                }
48
            }
49
        }
50
51
        if ($setCanonical) {
52
            $this->owner->view->registerLinkTag(
53
                [
54
                    'rel' => 'canonical',
55
                    'href' => $this->_canonical
56
                ]
57
            );
58
        }
59
    }
60
}