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

Workflow   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 78
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 3 1
A rules() 0 6 1
A getTotalStages() 0 3 1
A getStages() 0 4 1
A attributeLabels() 0 6 1
A attributeTypecast() 0 3 1
A getDetailStages() 0 11 1
1
<?php
2
3
namespace roaresearch\yii2\workflow\models;
4
5
use yii\db\ActiveQuery;
6
7
/**
8
 * Model class for table `{{%workflow}}`
9
 *
10
 * @property integer $id
11
 * @property string $name
12
 *
13
 * @property Stage[] $stages
14
 */
15
class Workflow extends \roaresearch\yii2\rmdb\models\PersistentEntity
16
{
17
    /**
18
     * @var string full class name of the model to be used for the relation
19
     * `getStages()`.
20
     */
21
    protected $stageClass = Stage::class;
22
23
    /**
24
     * @inheritdoc
25
     */
26 25
    public static function tableName()
27
    {
28 25
        return '{{%workflow}}';
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 19
    protected function attributeTypecast(): ?array
35
    {
36 19
        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' => 'Workflow name',
59 3
        ], parent::attributeLabels());
60
    }
61
62
    /**
63
     * @return ActiveQuery
64
     */
65 2
    public function getStages(): ActiveQuery
66
    {
67 2
        return $this->hasMany($this->stageClass, ['workflow_id' => 'id'])
68 2
            ->inverseOf('workflow');
69
    }
70
71
    /**
72
     * @return ActiveQuery
73
     */
74 1
    public function getDetailStages(): ActiveQuery
75
    {
76 1
        $query = $this->getStages();
77 1
        $query->multiple = false;
78
79 1
        return $query->select([
80 1
            'workflow_id',
81
            'totalStages' => 'count(distinct id)',
82 1
        ])->asArray()
83 1
        ->inverseOf(null)
84 1
        ->groupBy('workflow_id');
85
    }
86
87
    /**
88
     * @return int
89
     */
90 1
    public function getTotalStages(): int
91
    {
92 1
        return (int)$this->detailStages['totalStages'];
0 ignored issues
show
Bug Best Practice introduced by
The property detailStages does not exist on roaresearch\yii2\workflow\models\Workflow. Since you implemented __get, consider adding a @property annotation.
Loading history...
93
    }
94
}
95