Test Failed
Pull Request — master (#1)
by Carlos
04:03
created

FieldRuleProperty   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 68
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRule() 0 3 1
A attributeTypecast() 0 3 1
A rules() 0 19 1
A tableName() 0 3 1
A attributeLabels() 0 7 1
1
<?php
2
3
namespace roaresearch\yii2\formgenerator\models;
4
5
use yii\db\ActiveQuery;
6
7
/**
8
 * Model class for table `{{%formgenerator_field_rule_property}}`
9
 *
10
 * @property integer $rule_id
11
 * @property string $property
12
 * @property string $value
13
 *
14
 * @property FieldRule $rule
15
 */
16
class FieldRuleProperty extends \roaresearch\yii2\rmdb\models\Entity
17
{
18
    /**
19
     * @var string full class name of the model used in the relation
20
     * `getRules()`.
21
     */
22
    protected $ruleClass = FieldRule::class;
23
24
    /**
25
     * @inheritdoc
26
     */
27 9
    public static function tableName()
28
    {
29 9
        return '{{%formgenerator_field_rule_property}}';
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 7
    protected function attributeTypecast(): array
36
    {
37 7
        return parent::attributeTypecast() + ['rule_id' => 'integer'];
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 2
    public function rules()
44
    {
45
        return [
46 2
            [['rule_id', 'property', 'value'], 'required'],
47
            [['rule_id'], 'integer'],
48
            [
49
                ['rule_id'],
50
                'exist',
51
                'skipOnError' => true,
52
                'targetClass' => FieldRule::class,
53
                'targetAttribute' => ['rule_id' => 'id'],
54
            ],
55
            [['property', 'value'], 'trim'],
56
            [['property', 'value'], 'string'],
57
            [
58
                ['property'],
59
                'unique',
60
                'targetAttribute' => ['rule_id', 'property'],
61
                'message' => 'Property already in use for this rule.',
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 2
    public function attributeLabels()
70
    {
71 2
        return array_merge([
72 2
            'rule_id' => 'Rule ID',
73
            'property' => 'Property',
74
            'value' => 'Value',
75 2
        ], parent::attributeLabels());
76
    }
77
78
    /**
79
     * @return ActiveQuery
80
     */
81 7
    public function getRule(): ActiveQuery
82
    {
83 7
        return $this->hasOne($this->ruleClass, ['id' => 'rule_id']);
84
    }
85
}
86