Form   A
last analyzed

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 int $id
11
 * @property string $name
12
 * @property int $created_by
13
 * @property string $created_at
14
 * @property int $updated_by
15
 * @property string $updated_at
16
 *
17
 * @property Section[] $sections
18
 */
19
class Form extends \roaresearch\yii2\rmdb\models\Entity
20
{
21
    /**
22
     * @var string full class name of the model used in the relation
23
     * `getSections()`.
24
     */
25
    protected $sectionClass = Section::class;
26
27
    /**
28
     * @inheritdoc
29
     */
30 32
    public static function tableName()
31
    {
32 32
        return '{{%formgenerator_form}}';
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38 27
    protected function attributeTypecast(): array
39
    {
40 27
        return parent::attributeTypecast() + ['id' => 'integer'];
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 2
    public function rules()
47
    {
48
        return [
49 2
            [['name'], 'required'],
50
            [['name'], 'string', 'min' => 6],
51
            [['name'], 'unique'],
52
        ];
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 3
    public function attributeLabels()
59
    {
60 3
        return array_merge([
61 3
            'id' => 'ID',
62
            'name' => 'Form name',
63 3
        ], parent::attributeLabels());
64
    }
65
66
    /**
67
     * @return ActiveQuery
68
     */
69 1
    public function getSections(): ActiveQuery
70
    {
71 1
        return $this->hasMany($this->sectionClass, ['form_id' => 'id'])
72 1
            ->inverseOf('form');
73
    }
74
}
75