Completed
Push — master ( d0bd4d...b4b0fd )
by Igor
23:04
created

AuthItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 86
c 0
b 0
f 0
ccs 13
cts 15
cp 0.8667
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A attributeLabels() 0 9 1
A behaviors() 0 10 1
A events() 0 6 1
A find() 0 4 1
A isSuperUser() 0 4 1
A beforeDelete() 0 4 1
1
<?php
2
3
namespace app\models\entity;
4
5
use Yii;
6
use yii\behaviors\TimestampBehavior;
7
8
/**
9
 * This is the model class for table "{{%auth_item}}".
10
 *
11
 * @property string $name
12
 * @property integer $type
13
 * @property string $description
14
 * @property string $rule_name
15
 * @property string $data
16
 * @property integer $created_at
17
 * @property integer $updated_at
18
 */
19
class AuthItem extends \yii\db\ActiveRecord
20
{
21
    /**
22
     * @var array
23
     */
24
    public $roles;
25
    /**
26
     * @var array
27
     */
28
    public $permissions;
29
30
    /**
31
     * @inheritdoc
32
     */
33 14
    public static function tableName()
34
    {
35 14
        return Yii::$app->authManager->itemTable;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41 4
    public function attributeLabels()
42
    {
43
        return [
44 4
            'name'        => Yii::t('app', 'Name'),
45 4
            'description' => Yii::t('app', 'Description'),
46 4
            'roles'       => Yii::t('app', 'Inherit role'),
47 4
            'permissions' => Yii::t('app', 'Permissions'),
48
        ];
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 12
    public function behaviors()
55
    {
56
        return [
57
            [
58 12
                'class' => TimestampBehavior::class,
59
                'createdAtAttribute' => 'created_at',
60
                'updatedAtAttribute' => 'updated_at',
61
            ],
62
        ];
63
    }
64
65
    /**
66
     * @inheritdoc
67
     * @codeCoverageIgnore
68
     */
69
    public function events()
70
    {
71
        return [
72
            ActiveRecord::EVENT_BEFORE_DELETE => 'beforeDelete',
73
        ];
74
    }
75
76
    /**
77
     * @inheritdoc
78
     * @return \query\AuthItemQuery the active query used by this AR class.
79
     */
80 14
    public static function find()
81
    {
82 14
        return new \app\models\query\AuthItemQuery(get_called_class());
83
    }
84
85
    /**
86
     * Is SuperUser?
87
     *
88
     * @return bool
89
     */
90 2
    public function isSuperUser(): bool
91
    {
92 2
        return $this->name === User::ROLE_SUPERUSER;
93
    }
94
95
    /**
96
     * Deleting a file from the db and from the file system
97
     *
98
     * @return bool
99
     */
100
    public function beforeDelete()
101
    {
102
        return !$this->isSuperUser();
103
    }
104
}
105