FieldRulePropertySearch::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\formgenerator\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 `Form` records.
10
 * @author Angel (Faryshta) Guevara <[email protected]>
11
 */
12
class FieldRulePropertySearch extends FieldRuleProperty implements
13
    ResourceSearch
14
{
15
    /**
16
     * @inhertidoc
17
     */
18 1
    protected function slugBehaviorConfig(): array
19
    {
20
        return [
21 1
            'idAttribute' => [],
22
            'resourceName' => 'property',
23
        ];
24
    }
25
26
    /**
27
     * @inhertidoc
28
     */
29 1
    public function rules()
30
    {
31
        return [
32 1
            [['rule_id'], 'required'],
33
            [['rule_id', 'created_by'], 'integer'],
34
        ];
35
    }
36
37
    /**
38
     * @inhertidoc
39
     */
40 1
    public function search(
41
        array $params,
42
        ?string $formName = ''
43
    ): ?ActiveDataProvider {
44 1
        $this->load($params, $formName);
45 1
        if (!$this->validate()) {
46 1
            return null;
47
        }
48 1
        if (null === $this->rule) {
49 1
            throw new NotFoundHttpException('Rule not found');
50
        }
51 1
        $this->rule->checkAccess($params);
0 ignored issues
show
Bug introduced by
The method checkAccess() does not exist on roaresearch\yii2\formgenerator\models\FieldRule. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->rule->/** @scrutinizer ignore-call */ 
52
                     checkAccess($params);
Loading history...
52 1
        $class = get_parent_class();
53
54 1
        return new ActiveDataProvider([
55 1
            'query' => $class::find()->andFilterWhere([
56 1
                'rule_id' => $this->rule_id,
57 1
                'created_by' => $this->created_by,
58
            ]),
59
        ]);
60
    }
61
}
62