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.
Test Setup Failed
Push — filters ( fb817b...44fc4f )
by
unknown
11:13
created

Meta   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 8.89 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 12
c 1
b 1
f 0
lcom 0
cbo 0
dl 8
loc 90
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A rules() 8 8 1
A attributeLabels() 0 8 1
A search() 0 19 3
B registrationMeta() 0 30 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace app\modules\seo\models;
4
5
use app\backend\BackendModule;
6
use app\backend\components\BackendController;
7
use yii\data\ActiveDataProvider;
8
use yii\db\ActiveRecord;
9
10
/**
11
 * This is the model class for table "seo_meta".
12
 *
13
 * @property string $key
14
 * @property string $name
15
 * @property integer $content
16
 */
17
class Meta extends ActiveRecord
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public static function tableName()
23
    {
24
        return '{{%seo_meta}}';
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 View Code Duplication
    public function rules()
31
    {
32
        return [
33
            [['key', 'name', 'content'], 'required'],
34
            [['key'], 'unique'],
35
            [['key', 'name', 'content'], 'string', 'max' => 255]
36
        ];
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function attributeLabels()
43
    {
44
        return [
45
            'key' => \Yii::t('app', 'Key'),
46
            'name' => \Yii::t('app', 'Name'),
47
            'content' => \Yii::t('app', 'Content'),
48
        ];
49
    }
50
51
    /**
52
     * Search meta tags
53
     * @param $params
54
     * @return ActiveDataProvider
55
     */
56
    public function search($params)
57
    {
58
        $this->load($params);
59
        $query = self::find();
60
        foreach ($this->attributes as $name => $value) {
61
            if (!empty($value)) {
62
                $query->andWhere("`$name` LIKE :$name", [":$name" => "%$value%"]);
63
            }
64
        }
65
        $dataProvider = new ActiveDataProvider(
66
            [
67
                'query' => $query,
68
                'pagination' => [
69
                    'pageSize' => 10,
70
                ],
71
            ]
72
        );
73
        return $dataProvider;
74
    }
75
76
    public static function registrationMeta()
77
    {
78
79
        if (
80
            \Yii::$app->request->isAjax === false &&
81
            \Yii::$app->controller->module instanceof BackendModule === false &&
82
            \Yii::$app->controller instanceof BackendController === false
83
        ) {
84
           $cacheName = \Yii::$app->getModule('seo')->cacheConfig['metaCache']['name'];
85
           $cacheExpire = \Yii::$app->getModule('seo')->cacheConfig['metaCache']['expire'];
86
87
           if (\Yii::$app->getCache()->get($cacheName)) {
88
               $metas = \Yii::$app->getCache()->get($cacheName);
89
           } else {
90
               $metas = Meta::find()->all();
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
91
               \Yii::$app->getCache()->set($cacheName, $metas, $cacheExpire);
92
           }
93
           foreach ($metas as $meta) {
94
               \Yii::$app->controller->getView()->registerMetaTag(
95
                   [
96
                       'name' => $meta->name,
97
                       'content' => $meta->content,
98
                   ],
99
                   $meta->key
100
               );
101
           }
102
       }
103
104
105
    }
106
}
107