Assignment::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
ccs 6
cts 6
cp 1
crap 1
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\workflow\models;
4
5
use roaresearch\yii2\rmdb\models\Pivot;
6
use Yii;
7
use yii\db\ActiveQuery;
8
9
/**
10
 * @property int $process_id
11
 * @property int $user_id
12
 *
13
 * @property Process $process
14
 */
15
abstract class Assignment extends Pivot
16
{
17
    /**
18
     * @return string class name for the process this worklog is attached to.
19
     */
20
    abstract protected function processClass(): string;
21
22
    /**
23
     * @inheritdoc
24
     */
25 2
    public function rules()
26
    {
27
        return [
28 2
            [['process_id', 'user_id'], 'required'],
29
            [['process_id', 'user_id'], 'integer'],
30
            [
31
                ['process_id'],
32 2
                'exist',
33
                'targetAttribute' => ['process_id' => 'id'],
34 2
                'targetClass' => $this->processClass(),
35
            ],
36
            [
37
                ['user_id'],
38 2
                'exist',
39
                'targetAttribute' => ['user_id' => 'id'],
40 2
                'targetClass' => Yii::$app->user->identityClass,
41
            ],
42
        ];
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48 3
    public function attributeLabels()
49
    {
50 3
        return array_merge([
51 3
            'process_id' => 'Process ID',
52
            'user_id' => 'User ID',
53 3
        ], parent::attributeLabels());
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59 5
    public function init()
60
    {
61 5
        if (!is_subclass_of($this->processClass(), Process::class)) {
62
            throw new InvalidConfigException(
0 ignored issues
show
Bug introduced by
The type roaresearch\yii2\workflo...\InvalidConfigException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
                static::class . '::processClass() must extend '
64
                    . Process::class
65
            );
66
        }
67 5
        parent::init();
68 5
    }
69
70
    /**
71
     * @return ActiveQuery
72
     */
73 5
    public function getProcess(): ActiveQuery
74
    {
75 5
        return $this->hasOne($this->processClass(), ['id' => 'process_id']);
76
    }
77
}
78