SystemLogSearch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 51
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 7 1
A scenarios() 0 5 1
A search() 0 24 3
1
<?php
2
3
namespace monsterhunter\yii2\log\models\search;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
use monsterhunter\yii2\log\models\SystemLog;
9
10
/**
11
 * SystemLogSearch represents the models behind the search form about `backend\models\SystemLog`.
12
 */
13
class SystemLogSearch extends SystemLog
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 2
    public function rules()
19
    {
20
        return [
21 2
            [['id', 'log_time', 'message'], 'integer'],
22
            [['category', 'prefix', 'level'], 'safe'],
23
        ];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 2
    public function scenarios()
30
    {
31
        // bypass scenarios() implementation in the parent class
32 2
        return Model::scenarios();
33
    }
34
35
    /**
36
     * Creates data provider instance with search query applied
37
     * @return ActiveDataProvider
38
     */
39 2
    public function search($params)
40
    {
41 2
        $query = SystemLog::find();
42
43 2
        $dataProvider = new ActiveDataProvider([
44 2
            'query' => $query,
45
        ]);
46
47 2
        if (!($this->load($params) && $this->validate())) {
48
            return $dataProvider;
49
        }
50
51 2
        $query->andFilterWhere([
52 2
            'id' => $this->id,
53 2
            'level' => $this->level,
54 2
            'log_time' => $this->log_time,
55 2
            'message' => $this->message,
56
        ]);
57
58 2
        $query->andFilterWhere(['like', 'category', $this->category])
59 2
            ->andFilterWhere(['like', 'prefix', $this->prefix]);
60
61 2
        return $dataProvider;
62
    }
63
}
64