PageSearch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 65
loc 65
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 7 7 1
A scenarios() 5 5 1
B search() 35 35 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace app\modules\page\models;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
9
/**
10
 * PageSearch represents the model behind the search form about `app\modules\page\models\Page`.
11
 */
12 View Code Duplication
class PageSearch extends Page
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...
13
{
14
    /**
15
     * @inheritdoc
16
     */
17 1
    public function rules()
18
    {
19
        return [
20 1
            [['id'], 'integer'],
21
            [['key', 'title', 'content', 'description', 'created_at', 'updated_at'], 'safe'],
22
        ];
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 1
    public function scenarios()
29
    {
30
        // bypass scenarios() implementation in the parent class
31 1
        return Model::scenarios();
32
    }
33
34
    /**
35
     * Creates data provider instance with search query applied
36
     *
37
     * @param array $params
38
     *
39
     * @return ActiveDataProvider
40
     */
41 1
    public function search($params)
42
    {
43 1
        $query = Page::find();
44
45
        // add conditions that should always apply here
46
47 1
        $dataProvider = new ActiveDataProvider([
48
            'pagination' => [
49 1
                'pageSize' => Yii::$app->params['grid']['itemsPrePage'],
50
            ],
51 1
            'query' => $query,
52
        ]);
53
54 1
        $this->load($params);
55
56 1
        if (!$this->validate()) {
57
            // uncomment the following line if you do not want to return any records when validation fails
58
            // $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...
59
            return $dataProvider;
60
        }
61
62
        // grid filtering conditions
63 1
        $query->andFilterWhere([
64 1
            'id' => $this->id,
65 1
            'created_at' => $this->created_at,
66 1
            'updated_at' => $this->updated_at,
67
        ]);
68
69 1
        $query->andFilterWhere(['like', 'key', $this->key])
70 1
            ->andFilterWhere(['like', 'title', $this->title])
71 1
            ->andFilterWhere(['like', 'content', $this->content])
72 1
            ->andFilterWhere(['like', 'description', $this->description]);
73
74 1
        return $dataProvider;
75
    }
76
}
77