ProxySearch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scenarios() 0 4 1
A search() 0 29 2
A rules() 0 5 1
1
<?php
2
3
namespace app\modules\admin\models;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * ProxySearch represents the model behind the search form of `app\models\Proxy`.
10
 */
11
class ProxySearch extends Proxy
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function rules()
17
    {
18
        return [
19
            [['port'], 'integer'],
20
            [['ip', 'username', 'password', 'active'], 'safe'],
21
        ];
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function scenarios()
28
    {
29
        // bypass scenarios() implementation in the parent class
30
        return Model::scenarios();
31
    }
32
33
    /**
34
     * Creates data provider instance with search query applied
35
     *
36
     * @param array $params
37
     *
38
     * @return ActiveDataProvider
39
     */
40
    public function search($params)
41
    {
42
        $query = Proxy::find();
43
44
        // add conditions that should always apply here
45
46
        $dataProvider = new ActiveDataProvider([
47
            'query' => $query,
48
        ]);
49
50
        $this->load($params);
51
52
        if (!$this->validate()) {
53
            // uncomment the following line if you do not want to return any records when validation fails
54
            // $query->where('0=1');
55
            return $dataProvider;
56
        }
57
58
        // grid filtering conditions
59
        $query->andFilterWhere([
60
            'port' => $this->port,
61
        ]);
62
63
        $query->andFilterWhere(['like', 'ip', $this->ip])
64
            ->andFilterWhere(['like', 'username', $this->username])
65
            ->andFilterWhere(['like', 'password', $this->password])
66
            ->andFilterWhere(['active' => $this->active]);
67
68
        return $dataProvider;
69
    }
70
}
71