SettingSearch   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 20
c 3
b 1
f 0
dl 0
loc 52
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 4 1
A search() 0 28 2
1
<?php
2
3
namespace yii2mod\settings\models\search;
4
5
use yii\data\ActiveDataProvider;
6
use yii2mod\settings\models\SettingModel;
7
8
/**
9
 * Class SettingSearch
10
 *
11
 * @package yii2mod\settings\models\search
12
 */
13
class SettingSearch extends SettingModel
14
{
15
    /**
16
     * @var int the default page size
17
     */
18
    public $pageSize = 10;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function rules(): array
24
    {
25
        return [
26
            [['type', 'section', 'key', 'value', 'status', 'description'], 'safe'],
27
        ];
28
    }
29
30
    /**
31
     * Creates data provider instance with search query applied
32
     *
33
     * @param array $params
34
     *
35
     * @return ActiveDataProvider
36
     */
37
    public function search(array $params): ActiveDataProvider
38
    {
39
        $query = self::find();
40
41
        $dataProvider = new ActiveDataProvider([
42
            'query' => $query,
43
            'pagination' => [
44
                'pageSize' => $this->pageSize,
45
            ],
46
        ]);
47
48
        $this->load($params);
49
50
        if (!$this->validate()) {
51
            return $dataProvider;
52
        }
53
54
        $query->andFilterWhere([
55
            'status' => $this->status,
56
            'section' => $this->section,
57
            'type' => $this->type,
58
        ]);
59
60
        $query->andFilterWhere(['like', 'key', $this->key])
61
            ->andFilterWhere(['like', 'value', $this->value])
62
            ->andFilterWhere(['like', 'description', $this->description]);
63
64
        return $dataProvider;
65
    }
66
}
67