Test Failed
Pull Request — master (#1)
by Angel
03:51
created

Form   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 54
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSections() 0 4 1
A rules() 0 6 1
A tableName() 0 3 1
A attributeLabels() 0 6 1
A attributeTypecast() 0 3 1
1
<?php
2
3
namespace roaresearch\yii2\formgenerator\models;
4
5
use yii\db\ActiveQuery;
6
7
/**
8
 * Model class for table `{{%formgenerator_form}}`
9
 *
10
 * @property integer $id
11
 * @property string $name
12
 *
13
 * @property Section[] $sections
14
 */
15
class Form extends \roaresearch\yii2\rmdb\models\Entity
16
{
17
    /**
18
     * @var string full class name of the model used in the relation
19
     * `getSections()`.
20
     */
21
    protected $sectionClass = Section::class;
22
23
    /**
24
     * @inheritdoc
25
     */
26 32
    public static function tableName()
27
    {
28 32
        return '{{%formgenerator_form}}';
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 27
    protected function attributeTypecast(): array
35
    {
36 27
        return parent::attributeTypecast() + ['id' => 'integer'];
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 2
    public function rules()
43
    {
44
        return [
45 2
            [['name'], 'required'],
46
            [['name'], 'string', 'min' => 6],
47
            [['name'], 'unique'],
48
        ];
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 3
    public function attributeLabels()
55
    {
56 3
        return array_merge([
57 3
            'id' => 'ID',
58
            'name' => 'Form name',
59 3
        ], parent::attributeLabels());
60
    }
61
62
    /**
63
     * @return ActiveQuery
64
     */
65 1
    public function getSections(): ActiveQuery
66
    {
67 1
        return $this->hasMany($this->sectionClass, ['form_id' => 'id'])
68 1
            ->inverseOf('form');
69
    }
70
}
71