Issues (7)

src/Model/Setting.php (2 issues)

1
<?php
2
namespace RazonYang\Yii2\Setting\Model;
3
4
use yii\behaviors\TimestampBehavior;
5
use yii\db\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
    /**
20
     * @codeCoverageIgnore
21
     */
22
    public static function tableName()
23
    {
24
        return '{{%setting}}';
25
    }
26
27
    /**
28
     * @codeCoverageIgnore
29
     */
30
    public function behaviors()
31
    {
32
        return [
33
            [
34
                'class' => TimestampBehavior::class,
35
                'createdAtAttribute' => 'create_time',
36
                'updatedAtAttribute' => 'update_time',
37
            ],
38
        ];
39
    }
40
41
    /**
42
     * @codeCoverageIgnore
43
     */
44
    public function rules()
45
    {
46
        return [
47
            [['value', 'description'], 'required'],
48
            [['value', 'description'], 'string'],
49
            [['create_time', 'update_time'], 'integer'],
50
            ['value', 'validateValue'],
51
        ];
52
    }
53
54 5
    public function validateValue($attribute)
55
    {
56 5
        $rules = json_decode($this->rules, true);
0 ignored issues
show
Bug Best Practice introduced by
The property rules does not exist on RazonYang\Yii2\Setting\Model\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
57 5
        if (!is_array($rules)) {
58 1
            return;
59
        }
60
61 4
        foreach ($rules as $rule) {
62 4
            $params = $rule;
63 4
            $ruleName = $rule[0];
64 4
            unset($params[0]);
65 4
            $validator = Validator::createValidator($ruleName, $this, $attribute, $params);
66 4
            $validator->validateAttribute($this, $attribute);
67
        }
68 4
    }
69
70
    /**
71
     * @codeCoverageIgnore
72
     */
73
    public function attributeLabels()
74
    {
75
        return [
76
            'id' => Yii::t('app', 'ID'),
77
            'value' => Yii::t('app', $this->description),
0 ignored issues
show
Bug Best Practice introduced by
The property description does not exist on RazonYang\Yii2\Setting\Model\Setting. Since you implemented __get, consider adding a @property annotation.
Loading history...
78
            'create_time' => Yii::t('app', 'Create Time'),
79
            'update_time' => Yii::t('app', 'Update Time'),
80
        ];
81
    }
82
83
    /**
84
     * @codeCoverageIgnore
85
     */
86
    public function fields()
87
    {
88
        return [
89
            'id',
90
            'description',
91
            'value',
92
            'create_time',
93
            'update_time',
94
        ];
95
    }
96
}
97