SettingSearch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.45%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 55
ccs 21
cts 22
cp 0.9545
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 8 1
A scenarios() 0 5 1
B search() 0 27 3
1
<?php
2
/**
3
 * @link http://phe.me
4
 * @copyright Copyright (c) 2014 Pheme
5
 * @license MIT http://opensource.org/licenses/MIT
6
 */
7
8
namespace pheme\settings\models;
9
10
use Yii;
11
use yii\base\Model;
12
use yii\data\ActiveDataProvider;
13
14
/**
15
 * SettingSearch represents the model behind the search form about `pheme\settings\models\Setting`.
16
 *
17
 * @author Aris Karageorgos <[email protected]>
18
 */
19
class SettingSearch extends Setting
20
{
21
    /**
22
     * @return array
23
     */
24 1
    public function rules()
25
    {
26
        return [
27 1
            [['id'], 'integer'],
28 1
            [['active'], 'boolean'],
29 1
            [['type', 'section', 'key', 'value', 'created', 'modified'], 'safe'],
30 1
        ];
31
    }
32
33
    /**
34
     * @return array
35
     */
36 1
    public function scenarios()
37
    {
38
        // bypass scenarios() implementation in the parent class
39 1
        return Model::scenarios();
40
    }
41
42
    /**
43
     * @param $params
44
     * @return ActiveDataProvider
45
     */
46 1
    public function search($params)
47
    {
48 1
        $query = Setting::find();
49
50 1
        $dataProvider = new ActiveDataProvider(
51
            [
52 1
                'query' => $query,
53
            ]
54 1
        );
55
56 1
        if (!($this->load($params) && $this->validate())) {
57
            return $dataProvider;
58
        }
59
60 1
        $query->andFilterWhere(
61
            [
62 1
                'id' => $this->id,
63 1
                'active' => $this->active,
64 1
                'section' => $this->section,
65
            ]
66 1
        );
67
68 1
        $query->andFilterWhere(['like', 'key', $this->key])
69 1
            ->andFilterWhere(['like', 'value', $this->value]);
70
71 1
        return $dataProvider;
72
    }
73
}
74