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.

PropertyHandler::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace app\models;
4
5
use Yii;
6
use yii\caching\TagDependency;
7
use yii\db\ActiveRecord;
8
use yii\db\Query;
9
use yii\helpers\ArrayHelper;
10
11
/**
12
 * This is the model class for table "property_handler".
13
 *
14
 * @property integer $id
15
 * @property string $name
16
 * @property string $frontend_render_view
17
 * @property string $frontend_edit_view
18
 * @property string $backend_render_view
19
 * @property string $backend_edit_view
20
 * @property string $handler_class_name
21
 */
22
class PropertyHandler extends ActiveRecord
23
{
24
    private static $identity_map = [];
25
    private static $select_array_cache = null;
26
    private static $map_name_to_id = [];
27
28
    public function behaviors()
29
    {
30
        return [
31
            [
32
                '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...
33
            ],
34
        ];
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public static function tableName()
41
    {
42
        return '{{%property_handler}}';
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function rules()
49
    {
50
        return [
51
            [
52
                ['name', 'frontend_render_view', 'frontend_edit_view', 'backend_render_view',
53
                    'backend_edit_view', 'handler_class_name'],
54
                'required'
55
            ],
56
            [
57
                ['name', 'frontend_render_view', 'frontend_edit_view', 'backend_render_view',
58
                    'backend_edit_view', 'handler_class_name'],
59
                'string'
60
            ]
61
        ];
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67
    public function attributeLabels()
68
    {
69
        return [
70
            'id' => Yii::t('app', 'ID'),
71
            'name' => Yii::t('app', 'Name'),
72
            'frontend_render_view' => Yii::t('app', 'Frontend Render View'),
73
            'frontend_edit_view' => Yii::t('app', 'Frontend Edit View'),
74
            'backend_render_view' => Yii::t('app', 'Backend Render View'),
75
            'backend_edit_view' => Yii::t('app', 'Backend Edit View'),
76
            'handler_class_name' => Yii::t('app', 'Handler Class Name'),
77
        ];
78
    }
79
80
    /**
81
     * Возвращает модель по ID с использованием IdentityMap
82
     */
83 View Code Duplication
    public static function findById($id)
84
    {
85
        if (!isset(static::$identity_map[$id])) {
86
            static::$identity_map[$id] = Yii::$app->cache->get('PropertyHandler: ' . $id);
87
            if (static::$identity_map[$id] === false) {
88
                static::$identity_map[$id] = PropertyHandler::findOne($id);
89
                if (static::$identity_map[$id] !== null) {
90
                    Yii::$app->cache->set(
91
                        'PropertyHandler: ' . $id,
92
                        static::$identity_map[$id],
93
                        86400,
94
                        new TagDependency(
95
                            [
96
                                'tags' => [
97
                                    \devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id),
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...
98
                                ],
99
                            ]
100
                        )
101
                    );
102
                }
103
            }
104
        }
105
        return static::$identity_map[$id];
106
    }
107
108
    /**
109
     * Возвращает список всех объектов
110
     * Ключ - ID
111
     * Значение - name
112
     * Используется для фильтрации в таблицах и выборе объекта в форме
113
     */
114 View Code Duplication
    public static function getSelectArray()
115
    {
116
        if (static::$select_array_cache === null) {
117
            static::$select_array_cache = Yii::$app->cache->get('PropertyHandlersList');
118
            if (static::$select_array_cache === false) {
119
                $rows = (new Query())
120
                    ->select('id, name')
121
                    ->from(PropertyHandler::tableName())
122
                    ->all();
123
                static::$select_array_cache = ArrayHelper::map($rows, 'id', 'name');
124
                Yii::$app->cache->set(
125
                    'PropertyHandlersList',
126
                    static::$select_array_cache,
127
                    86400,
128
                    new TagDependency(
129
                        [
130
                            'tags' => [
131
                                \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...
132
                            ],
133
                        ]
134
                    )
135
                );
136
            }
137
        }
138
        return static::$select_array_cache;
139
    }
140
141
    /**
142
     * @param $name
143
     * @return null|int
144
     */
145
    public static function findByName($name)
146
    {
147
        if (empty(static::$map_name_to_id)) {
148
            $cache_key = 'PropertyHandler:MapToId';
149
            static::$map_name_to_id = Yii::$app->cache->get($cache_key);
150
            if (false === static::$map_name_to_id) {
151
                $query = static::find()->asArray()->all();
152
                foreach ($query as $row) {
153
                    static::$map_name_to_id[$row['name']] = intval($row['id']);
154
                }
155
                Yii::$app->cache->set(
156
                    $cache_key,
157
                    static::$map_name_to_id,
158
                    0,
159
                    new TagDependency(
160
                        [
161
                            'tags' => [
162
                                \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...
163
                            ]
164
                        ]
165
                    )
166
                );
167
            }
168
        }
169
170
        if (isset(static::$map_name_to_id[$name])) {
171
            return static::$map_name_to_id[$name];
172
        }
173
174
        return null;
175
    }
176
}
177