Passed
Push — master ( 536f48...741d19 )
by Carlos
01:52 queued 12s
created

Workflow   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 47
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLinks() 0 4 1
A slugBehaviorConfig() 0 11 3
A extraFields() 0 3 1
1
<?php
2
3
namespace roaresearch\yii2\workflow\roa\models;
4
5
use roaresearch\yii2\roa\hal\{Contract, ContractTrait};
6
use roaresearch\yii2\workflow\models as base;
7
use yii\web\NotFoundHttpException;
8
9
/**
10
 * ROA contract to handle workflow records.
11
 */
12
class Workflow extends base\Workflow implements Contract
13
{
14
    use ContractTrait {
15
        getLinks as getContractLinks;
16
    }
17
18
    /**
19
     * @inheritdoc
20
     */
21
    protected $stageClass = Stage::class;
22
23
    /**
24
     * @inheritdoc
25
     */
26 19
    protected function slugBehaviorConfig(): array
27
    {
28
        return [
29 19
            'resourceName' => 'workflow',
30 19
            'checkAccess' => function ($params) {
31
                if (
32 19
                    isset($params['workflow_id'])
33 19
                    && $this->id != $params['workflow_id']
34
                ) {
35 4
                    throw new NotFoundHttpException(
36 4
                        'Workflow not associated to element.'
37
                    );
38
                }
39 19
            },
40
        ];
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 5
    public function getLinks()
47
    {
48 5
        return array_merge($this->getContractLinks(), [
49 5
            'stages' => $this->getSelfLink() . '/stage',
50
        ]);
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56 5
    public function extraFields()
57
    {
58 5
        return ['stages', 'detailStages', 'totalStages'];
59
    }
60
}
61