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.

View::getViewById()   B
last analyzed

Complexity

Conditions 8
Paths 17

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.1475
c 0
b 0
f 0
cc 8
nc 17
nop 1
1
<?php
2
3
namespace app\models;
4
5
use app\traits\LoadModel;
6
use Yii;
7
use yii\caching\TagDependency;
8
use yii\data\ActiveDataProvider;
9
use yii\db\ActiveRecord;
10
11
/**
12
 * This is the model class for table "view".
13
 *
14
 * @property integer $id
15
 * @property string $name
16
 * @property string $view
17
 */
18
class View extends ActiveRecord
19
{
20
    private static $identity_map = null;
21
22
    use LoadModel;
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public static function tableName()
28
    {
29
        return '{{%view}}';
30
    }
31
32
    public function behaviors()
33
    {
34
        return [
35
            [
36
                'class' => \devgroup\TagDependencyHelper\ActiveRecordHelper::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
37
            ],
38
        ];
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function rules()
45
    {
46
        return [
47
            [['name', 'view', 'category', 'internal_name'], 'string'],
48
            [['name', 'view'], 'required'],
49
        ];
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function attributeLabels()
56
    {
57
        return [
58
            'id' => Yii::t('app', 'ID'),
59
            'name' => Yii::t('app', 'Name'),
60
            'view' => Yii::t('app', 'View'),
61
            'category' => Yii::t('app', 'Category'),
62
            'internal_name' => Yii::t('app', 'Internal name'),
63
        ];
64
    }
65
66
    /**
67
     * Поиск
68
     * @param $params
69
     * @return ActiveDataProvider
70
     */
71 View Code Duplication
    public function search($params)
72
    {
73
        /* @var $query \yii\db\ActiveQuery */
74
        $dataProvider = new ActiveDataProvider(
75
            [
76
                'query' => $query = self::find(),
77
                'pagination' => [
78
                    'pageSize' => 20,
79
                ],
80
            ]
81
        );
82
        if (!($this->load($params))) {
83
            return $dataProvider;
84
        }
85
        $query->andFilterWhere(['id' => $this->id]);
86
        $query->andFilterWhere(['like', 'name', $this->name]);
87
        $query->andFilterWhere(['like', 'category', $this->category]);
0 ignored issues
show
Documentation introduced by
The property category does not exist on object<app\models\View>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
88
        return $dataProvider;
89
    }
90
91
    /**
92
     * @param null $id
93
     * @return string|null
94
     */
95
    public static function getViewById($id = null)
96
    {
97
        if (null === $id) {
98
            return null;
99
        }
100
        if (null === static::$identity_map) {
101
            $cacheKey = static::className().'ModelMap';
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
102
            if (false === $map = Yii::$app->cache->get($cacheKey)) {
103
                if (null === $_model = static::find()->asArray()->all()) {
104
                    $map = [];
105
                } else {
106
                    foreach ($_model as $v) {
107
                        $map[$v['id']] = $v['view'];
108
                    }
109
                }
110
            }
111
            Yii::$app->cache->set(
112
                $cacheKey,
113
                static::$identity_map = $map,
114
                0,
115
                new TagDependency(
116
                    [
117
                        'tags' => [
118
                            \devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(static::className()),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
119
                        ],
120
                    ]
121
                )
122
            );
123
        }
124
        return (array_key_exists($id, static::$identity_map) && !empty(static::$identity_map[$id]))
125
            ? static::$identity_map[$id]
126
            : null;
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public static function getAllAsArray()
133
    {
134
        if (null === $model = static::find()->asArray()->all()) {
135
            return [];
136
        }
137
        $result = [0 => Yii::t('app', 'Parent')];
138
        foreach ($model as $item) {
139
            $result[$item['id']] = $item['name'];
140
        }
141
        return $result;
142
    }
143
144
    /*
145
     *
146
     */
147
    public function beforeDelete()
148
    {
149
        ViewObject::deleteByViewId($this->id);
150
        return parent::beforeDelete();
151
    }
152
}
153