Test Failed
Pull Request — master (#5)
by aguevaraIL
07:24
created

CreditWorkLog::rules()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.8666
1
<?php
2
3
namespace app\models;
4
5
use roaresearch\yii2\workflow\models\Stage;
6
7
class CreditWorkLog extends \roaresearch\yii2\workflow\models\WorkLog
8
{
9
    /**
10
     * @inheritdoc
11
     */   public static function tableName()
12
    {
13
        return '{{%credit_worklog}}';
14
    }
15
16
    /**
17
     * @inheritdoc
18
     */
19
    protected function processClass(): string
20
    {
21
        return Credit::class;
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function rules()
28
    {
29
        return array_merge(parent::rules(), [
30
            [
31
                ['stage_id'],
32
                'exist',
33
                'skipOnError' => true,
34
                'targetClass' => Stage::class,
35
                'targetAttribute' => ['stage_id' => 'id'],
36
                'on' => [self::SCENARIO_INITIAL],
37
                'filter' => function ($q) {
38
                    if (!$this->process->hasErrors()) {
39
                        $q->andWhere([
40
                            'workflow_id' => $this->process->workflow_id,
0 ignored issues
show
Bug Best Practice introduced by
The property workflow_id does not exist on roaresearch\yii2\workflow\models\Process. Since you implemented __get, consider adding a @property annotation.
Loading history...
41
                        ]);
42
                    }
43
                },
44
                'message' => 'Stage "{value}" does not belong to the workflow.',
45
            ],
46
        ]);
47
    }
48
}
49