Completed
Push — master ( e1cfa8...b8fd6b )
by Razon
03:50 queued 01:06
created

Setting::attributeLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace App\Setting\Storage\Db;
3
4
use App\Db\TimestampBehavior;
5
use App\Model\ActiveRecord;
6
use yii\validators\Validator;
7
use Yii;
8
9
/**
10
 * This is the model class for table "{{%setting}}".
11
 *
12
 * @property string $id ID
13
 * @property string $value Value
14
 * @property int $create_time Create Time
15
 * @property int $update_time Update Time
16
 */
17
class Setting extends ActiveRecord
18
{
19
    public static function tableName()
20
    {
21
        return '{{%setting}}';
22
    }
23
24
    public function behaviors()
25
    {
26
        return [
27
            TimestampBehavior::class,
28
        ];
29
    }
30
31
    public function rules()
32
    {
33
        return [
34
            [['value', 'description'], 'required'],
35
            [['value', 'description'], 'string'],
36
            [['create_time', 'update_time'], 'integer'],
37
            ['value', 'validateValue'],
38
        ];
39
    }
40
41
    public function validateValue($attribute)
42
    {
43
        $rules = json_decode($this->rules, true);
0 ignored issues
show
Bug Best Practice introduced by
The property rules does not exist on App\Setting\Storage\Db\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
44
        if (!is_array($rules)) {
45
            return;
46
        }
47
48
        foreach ($rules as $rule) {
49
            $params = $rule;
50
            $ruleName = $rule[0];
51
            unset($params[0]);
52
            $validator = Validator::createValidator($ruleName, $this, $attribute, $params);
53
            $validator->validateAttribute($this, $attribute);
54
        }
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function attributeLabels()
61
    {
62
        return [
63
            'id' => Yii::t('app', 'ID'),
64
            'value' => Yii::t('app', $this->description),
0 ignored issues
show
Bug Best Practice introduced by
The property description does not exist on App\Setting\Storage\Db\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
            'create_time' => Yii::t('app', 'Create Time'),
66
            'update_time' => Yii::t('app', 'Update Time'),
67
        ];
68
    }
69
70
    public function fields()
71
    {
72
        return [
73
            'id',
74
            'description',
75
            'value',
76
            'create_time',
77
            'update_time',
78
        ];
79
    }
80
}
81