CommentSearch   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 22
c 1
b 0
f 1
dl 0
loc 56
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 31 2
A rules() 0 5 1
1
<?php
2
3
namespace yii2mod\comments\models\search;
4
5
use yii\data\ActiveDataProvider;
6
use yii2mod\comments\models\CommentModel;
7
8
/**
9
 * Class CommentSearch
10
 *
11
 * @package yii2mod\comments\models\search
12
 */
13
class CommentSearch extends CommentModel
14
{
15
    /**
16
     * @var int the default page size
17
     */
18
    public $pageSize = 10;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function rules()
24
    {
25
        return [
26
            [['id', 'createdBy', 'status'], 'integer'],
27
            [['content', 'relatedTo'], 'safe'],
28
        ];
29
    }
30
31
    /**
32
     * Creates data provider instance with search query applied
33
     *
34
     * @param $params
35
     *
36
     * @return ActiveDataProvider
37
     */
38
    public function search(array $params)
39
    {
40
        $query = CommentModel::find();
41
42
        $dataProvider = new ActiveDataProvider([
43
            'query' => $query,
44
            'pagination' => [
45
                'pageSize' => $this->pageSize,
46
            ],
47
        ]);
48
49
        $dataProvider->setSort([
50
            'defaultOrder' => ['id' => SORT_DESC],
51
        ]);
52
53
        $this->load($params);
54
55
        if (!$this->validate()) {
56
            return $dataProvider;
57
        }
58
59
        $query->andFilterWhere([
60
            'id' => $this->id,
61
            'createdBy' => $this->createdBy,
62
            'status' => $this->status,
63
        ]);
64
65
        $query->andFilterWhere(['like', 'content', $this->content]);
66
        $query->andFilterWhere(['like', 'relatedTo', $this->relatedTo]);
67
68
        return $dataProvider;
69
    }
70
}
71