TransitionPermissionSearch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 22 4
A rules() 0 5 1
1
<?php
2
3
namespace roaresearch\yii2\workflow\roa\models;
4
5
use roaresearch\yii2\roa\ResourceSearch;
6
use yii\{data\ActiveDataProvider, web\NotFoundHttpException};
7
8
/**
9
 * Contract to filter and sort collections of `TransitionPermission` records.
10
 *
11
 * @author Angel (Faryshta) Guevara <[email protected]>
12
 */
13
class TransitionPermissionSearch extends TransitionPermission implements
14
    ResourceSearch
15
{
16
    /**
17
     * @inhertidoc
18
     */
19 1
    public function rules()
20
    {
21
        return [
22 1
            [['created_by', 'source_stage_id', 'target_stage_id'], 'integer'],
23
            [['permission'], 'string'],
24
        ];
25
    }
26
27
    /**
28
     * @inhertidoc
29
     */
30 1
    public function search(
31
        array $params,
32
        ?string $formName = ''
33
    ): ?ActiveDataProvider {
34 1
        $this->load($params, $formName);
35 1
        if (!$this->validate()) {
36 1
            return null;
37
        }
38
        if (
39 1
            null === $this->transition
40 1
            || $this->sourceStage->workflow_id != $params['workflow_id']
41
        ) {
42 1
            throw new NotFoundHttpException('Unexistant permission path.');
43
        }
44
45 1
        $class = get_parent_class();
46 1
        return new ActiveDataProvider([
47 1
            'query' => $class::find()->andFilterWhere([
48 1
                    'target_stage_id' => $this->target_stage_id,
49 1
                    'source_stage_id' => $this->source_stage_id,
50
                ])
51 1
                ->andFilterWhere(['like', 'permission', $this->permission]),
52
        ]);
53
    }
54
}
55