Workflow   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 55
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLinks() 0 4 1
A slugBehaviorConfig() 0 11 3
A extraFields() 0 3 1
A getStages() 0 3 1
1
<?php
2
3
namespace roaresearch\yii2\workflow\roa\models;
4
5
use roaresearch\yii2\rmdb\SoftDeleteActiveQuery;
6
use roaresearch\yii2\roa\hal\{Contract, ContractTrait};
7
use roaresearch\yii2\workflow\models as base;
8
use yii\web\NotFoundHttpException;
9
10
/**
11
 * ROA contract to handle workflow records.
12
 */
13
class Workflow extends base\Workflow implements Contract
14
{
15
    use ContractTrait {
16
        getLinks as getContractLinks;
17
    }
18
19
    /**
20
     * @inheritdoc
21
     */
22
    protected $stageClass = Stage::class;
23
24
    /**
25
     * @inheritdoc
26
     */
27 19
    protected function slugBehaviorConfig(): array
28
    {
29
        return [
30 19
            'resourceName' => 'workflow',
31 19
            'checkAccess' => function ($params) {
32
                if (
33 19
                    isset($params['workflow_id'])
34 19
                    && $this->id != $params['workflow_id']
35
                ) {
36 4
                    throw new NotFoundHttpException(
37 4
                        'Workflow not associated to element.'
38
                    );
39
                }
40 19
            },
41
        ];
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 5
    public function getLinks()
48
    {
49 5
        return array_merge($this->getContractLinks(), [
50 5
            'stages' => $this->getSelfLink() . '/stage',
51
        ]);
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 5
    public function extraFields()
58
    {
59 5
        return ['stages', 'detailStages', 'totalStages'];
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 3
    public function getStages(): SoftDeleteActiveQuery
66
    {
67 3
        return parent::getStages()->notDeleted();
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getStages()->notDeleted() returns the type roaresearch\yii2\rmdb\So...eteActiveQueryInterface which includes types incompatible with the type-hinted return roaresearch\yii2\rmdb\SoftDeleteActiveQuery.
Loading history...
68
    }
69
}
70