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

Workflow::slugBehaviorConfig()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 1
nop 0
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 10
c 0
b 0
f 0
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