Completed
Push — master ( ae08e3...aed614 )
by Alexey
03:06
created

UserSearch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 67
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 5 1
B search() 0 38 2
A scenarios() 0 4 1
1
<?php
2
3
namespace modules\admin\models\search;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
use modules\admin\models\User;
9
10
/**
11
 * UserSearch represents the model behind the search form of `modules\admin\models\User`.
12
 */
13
class UserSearch extends User
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function rules()
19
    {
20
        return [
21
            [['id', 'status', 'last_visit', 'created_at', 'updated_at', 'registration_type'], 'integer'],
22
            [['username', 'auth_key', 'password_hash', 'password_reset_token', 'email_confirm_token', 'email', 'first_name', 'last_name'], 'safe'],
23
        ];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function scenarios()
30
    {
31
        // bypass scenarios() implementation in the parent class
32
        return Model::scenarios();
0 ignored issues
show
Bug Best Practice introduced by
The method yii\base\Model::scenarios() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        return Model::/** @scrutinizer ignore-call */ scenarios();
Loading history...
33
    }
34
35
    /**
36
     * Creates data provider instance with search query applied
37
     *
38
     * @param array $params
39
     *
40
     * @return ActiveDataProvider
41
     */
42
    public function search($params)
43
    {
44
        $query = User::find();
45
46
        // add conditions that should always apply here
47
48
        $dataProvider = new ActiveDataProvider([
49
            'query' => $query,
50
        ]);
51
52
        $this->load($params);
53
54
        if (!$this->validate()) {
55
            // uncomment the following line if you do not want to return any records when validation fails
56
            // $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...
57
            return $dataProvider;
58
        }
59
60
        // grid filtering conditions
61
        $query->andFilterWhere([
62
            'id' => $this->id,
63
            'status' => $this->status,
64
            'last_visit' => $this->last_visit,
65
            'created_at' => $this->created_at,
66
            'updated_at' => $this->updated_at,
67
            'registration_type' => $this->registration_type,
68
        ]);
69
70
        $query->andFilterWhere(['like', 'username', $this->username])
71
            ->andFilterWhere(['like', 'auth_key', $this->auth_key])
72
            ->andFilterWhere(['like', 'password_hash', $this->password_hash])
73
            ->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])
74
            ->andFilterWhere(['like', 'email_confirm_token', $this->email_confirm_token])
75
            ->andFilterWhere(['like', 'email', $this->email])
76
            ->andFilterWhere(['like', 'first_name', $this->first_name])
77
            ->andFilterWhere(['like', 'last_name', $this->last_name]);
78
79
        return $dataProvider;
80
    }
81
}
82