Html::search()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 12

Duplication

Lines 26
Ratio 89.66 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 26
loc 29
rs 8.8571
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
namespace app\modules\prototype\models\search;
4
5
use app\modules\prototype\models\Html as HtmlModel;
6
use Yii;
7
use yii\base\Model;
8
use yii\data\ActiveDataProvider;
9
10
/**
11
 * Html represents the model behind the search form about `app\modules\prototype\models\Html`.
12
 */
13 View Code Duplication
class Html extends HtmlModel
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function rules()
19
    {
20
        return [
21
            [['id'], 'integer'],
22
            [['key', 'value'], '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();
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 = HtmlModel::find();
45
46
        $dataProvider = new ActiveDataProvider(
47
            [
48
                'query' => $query,
49
            ]
50
        );
51
52
        $this->load($params);
53
54
        if (!$this->validate()) {
55
            // uncomment the following line if you do not want to 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
        $query->andFilterWhere(
61
            [
62
                'id' => $this->id,
63
            ]
64
        );
65
66
        $query->andFilterWhere(['like', 'key', $this->key])
67
            ->andFilterWhere(['like', 'value', $this->value]);
68
69
        return $dataProvider;
70
    }
71
}