AuditMailSearch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 7 1
A scenarios() 0 5 1
A search() 0 32 3
1
<?php
2
3
namespace bedezign\yii2\audit\models;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * AuditMailSearch
10
 * @package bedezign\yii2\audit\models
11
 */
12
class AuditMailSearch extends AuditMail
13
{
14
    /**
15
     * @return array
16
     */
17 9
    public function rules()
18
    {
19
        // only fields in rules() are searchable
20
        return [
21 9
            [['id', 'entry_id', 'successful', 'to', 'from', 'reply', 'cc', 'bcc', 'subject', 'created'], 'safe'],
22 9
        ];
23
    }
24
25
    /**
26
     * @return array
27
     */
28 9
    public function scenarios()
29
    {
30
        // bypass scenarios() implementation in the parent class
31 9
        return Model::scenarios();
32
    }
33
34
    /**
35
     * @param $params
36
     * @return ActiveDataProvider
37
     */
38 9
    public function search($params)
39
    {
40 9
        $query = AuditMail::find();
41
42 9
        $dataProvider = new ActiveDataProvider([
43 9
            'query' => $query,
44
            'sort' => [
45
                'defaultOrder' => [
46
                    'id' => SORT_DESC
47 9
                ]
48 9
            ]
49 9
        ]);
50
51
        // load the search form data and validate
52 9
        if (!($this->load($params) && $this->validate())) {
53 6
            return $dataProvider;
54
        }
55
56
        // adjust the query by adding the filters
57 3
        $query->andFilterWhere(['id' => $this->id]);
58 3
        $query->andFilterWhere(['entry_id' => $this->entry_id]);
59 3
        $query->andFilterWhere(['successful' => $this->successful]);
60 3
        $query->andFilterWhere(['like', 'to', $this->to]);
61 3
        $query->andFilterWhere(['like', 'from', $this->from]);
62 3
        $query->andFilterWhere(['like', 'reply', $this->reply]);
63 3
        $query->andFilterWhere(['like', 'cc', $this->cc]);
64 3
        $query->andFilterWhere(['like', 'bcc', $this->bcc]);
65 3
        $query->andFilterWhere(['like', 'subject', $this->subject]);
66 3
        $query->andFilterWhere(['like', 'created', $this->created]);
67
68 3
        return $dataProvider;
69
    }
70
71
}
72