Completed
Push — master ( e4197d...f733ed )
by Igor
11:05 queued 09:33
created

AuthItemSearch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 45
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

2 Methods

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