AuthItemSearch::search()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
ccs 8
cts 10
cp 0.8
cc 3
nc 2
nop 1
crap 3.072
1
<?php
2
3
namespace app\modules\admin\models\search;
4
5
use yii\data\ActiveDataProvider;
6
use app\models\entity\AuthItem;
7
8
/**
9
 * AuthItemSearch represents the model behind the search form about `app\models\entity\AuthItem`
10
 */
11
class AuthItemSearch extends AuthItem
12
{
13
    /**
14
     * @inheritdoc
15
     */
16 4
    public function rules()
17
    {
18
        return [
19 4
            ['name', 'string'],
20
        ];
21
    }
22
23
    /**
24
     * Search by request criteria
25
     *
26
     * @param array|null Filter params
27
     * @return ActiveDataProvider Data provider
28
     */
29 4
    public function search($params)
30
    {
31 4
        $query = AuthItem::find();
32
33 4
        $dataProvider = new ActiveDataProvider([
34 4
            'query' => $query,
35
            'sort' => [
36
                'defaultOrder' => [
37 4
                    'name' => SORT_ASC,
38
                ]
39
            ],
40
            'pagination' => [
41
                'pageSize' => 50,
42
            ],
43
        ]);
44
45 4
        $query->andFilterWhere(['type' => \yii\rbac\Item::TYPE_ROLE]);
46
47 4
        if (!($this->load($params) && $this->validate())) {
48 4
            return $dataProvider;
49
        }
50
51
        $query->andFilterWhere(['like', 'name', $this->name]);
52
53
        return $dataProvider;
54
    }
55
}
56