SectionFieldSearch::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
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;
7
8
/**
9
 * Contract to filter and sort collections of `SectionField` records.
10
 *
11
 * @author Angel (Faryshta) Guevara <[email protected]>
12
 */
13
class SectionFieldSearch extends SectionField implements ResourceSearch
14
{
15
    /**
16
     * @inhertidoc
17
     */
18 1
    protected function slugBehaviorConfig(): array
19
    {
20
        return [
21 1
            'idAttribute' => [],
22
            'resourceName' => 'field',
23
            'parentSlugRelation' => 'section',
24
        ];
25
    }
26
27
    /**
28
     * @inhertidoc
29
     */
30 1
    public function rules()
31
    {
32
        return [
33 1
            [['section_id'], 'required'],
34
            [['section_id', 'position', 'created_by'], 'integer'],
35
            [['label'], 'string'],
36
        ];
37
    }
38
39
    /**
40
     * @inhertidoc
41
     */
42 1
    public function search(
43
        array $params,
44
        ?string $formName = ''
45
    ): ?ActiveDataProvider {
46 1
        $this->load($params, $formName);
47 1
        $this->getBehavior('position')->attachValidators = false;
48 1
        if (!$this->validate()) {
49 1
            return null;
50
        }
51
52 1
        $this->checkAccess($params);
0 ignored issues
show
Bug introduced by
The method checkAccess() does not exist on roaresearch\yii2\formgen...dels\SectionFieldSearch. 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->/** @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
                    'section_id' => $this->section_id,
58 1
                    'created_by' => $this->created_by,
59 1
                    'position' => $this->position,
60
                ])
61 1
                ->andFilterWhere(['like', 'label', $this->label]),
62
            'sort' => [
63
                'defaultOrder' => [
64 1
                    'position' => SORT_ASC,
65
                ],
66
            ],
67
        ]);
68
    }
69
}
70