Test Failed
Pull Request — master (#1)
by Angel
03:51
created

FieldRulePropertySearch   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 46
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 18 3
A rules() 0 5 1
A slugBehaviorConfig() 0 5 1
1
<?php
2
3
namespace roaresearch\yii2\formgenerator\roa\models;
4
5
use roaresearch\yii2\roa\ResourceSearch;
6
use yii\data\ActiveDataProvider;
7
use yii\web\NotFoundHttpException;
8
9
/**
10
 * Contract to filter and sort collections of `Form` records.
11
 * @author Angel (Faryshta) Guevara <[email protected]>
12
 */
13
class FieldRulePropertySearch extends FieldRuleProperty implements
14
    ResourceSearch
15
{
16
    /**
17
     * @inhertidoc
18
     */
19 1
    protected function slugBehaviorConfig(): array
20
    {
21
        return [
22 1
            'idAttribute' => [],
23
            'resourceName' => 'property',
24
        ];
25
    }
26
27
    /**
28
     * @inhertidoc
29
     */
30 1
    public function rules()
31
    {
32
        return [
33 1
            [['rule_id'], 'required'],
34
            [['rule_id', 'created_by'], 'integer'],
35
        ];
36
    }
37
38
    /**
39
     * @inhertidoc
40
     */
41 1
    public function search(
42
        array $params,
43
        ?string $formName = ''
44
    ): ?ActiveDataProvider {
45 1
        $this->load($params, $formName);
46 1
        if (!$this->validate()) {
47 1
            return null;
48
        }
49 1
        if (null === $this->rule) {
50 1
            throw new NotFoundHttpException('Rule not found');
51
        }
52 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

52
        $this->rule->/** @scrutinizer ignore-call */ 
53
                     checkAccess($params);
Loading history...
53 1
        $class = get_parent_class();
54
55 1
        return new ActiveDataProvider([
56 1
            'query' => $class::find()->andFilterWhere([
57 1
                'rule_id' => $this->rule_id,
58 1
                'created_by' => $this->created_by,
0 ignored issues
show
Bug Best Practice introduced by
The property created_by does not exist on roaresearch\yii2\formgen...FieldRulePropertySearch. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
            ]),
60
        ]);
61
    }
62
}
63