Completed
Push — master ( 265344...30de12 )
by Pavel
01:39
created

UserSearch::scenarios()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace inblank\activeuser\models;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * UserSearch represents the model behind the search form about `inblank\activeuser\models\User`.
10
 */
11
class UserSearch extends User
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function rules()
17
    {
18
        return [
19
            [['id', 'status', 'gender'], 'integer'],
20
            [['email', 'name', 'birth', 'registered_at'], '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 = User::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');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
            return $dataProvider;
56
        }
57
58
        // grid filtering conditions
59
        $query->andFilterWhere([
60
            'id' => $this->id,
61
            'status' => $this->status,
62
            'gender' => $this->gender,
63
        ]);
64
65
        $query->andFilterWhere(['like', 'email', $this->email])
66
            ->andFilterWhere(['like', 'name', $this->name])
67
            ->andFilterWhere(['like', 'birth', $this->birth])
68
            ->andFilterWhere(['like', 'registered_at', $this->registered_at]);
69
70
        return $dataProvider;
71
    }
72
}
73