Taxonomy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
c 4
b 0
f 0
lcom 1
cbo 4
dl 57
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 7 7 1
A scenarios() 5 5 1
B search() 28 28 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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace common\models\search;
9
10
use common\models\Taxonomy as TaxonomyModel;
11
use Yii;
12
use yii\base\Model;
13
use yii\data\ActiveDataProvider;
14
15
/**
16
 * Taxonomy represents the model behind the search form about `common\models\Taxonomy`.
17
 *
18
 * @author Agiel K. Saputra <[email protected]>
19
 * @since 0.1.0
20
 */
21 View Code Duplication
class Taxonomy extends TaxonomyModel
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...
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function rules()
27
    {
28
        return [
29
            [['id', 'hierarchical', 'menu_builder'], 'integer'],
30
            [['name', 'slug', 'singular_name', 'plural_name'], 'safe'],
31
        ];
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function scenarios()
38
    {
39
        // bypass scenarios() implementation in the parent class
40
        return Model::scenarios();
41
    }
42
43
    /**
44
     * Creates data provider instance with search query applied
45
     *
46
     * @param array $params
47
     * @return ActiveDataProvider
48
     */
49
    public function search($params)
50
    {
51
        $query = TaxonomyModel::find();
52
53
        $dataProvider = new ActiveDataProvider([
54
            'query' => $query,
55
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
56
        ]);
57
58
        $this->load($params);
59
60
        if (!$this->validate()) {
61
            return $dataProvider;
62
        }
63
64
        $query->andFilterWhere([
65
            'id' => $this->id,
66
            'hierarchical' => $this->hierarchical,
67
            'menu_builder' => $this->menu_builder,
68
        ]);
69
70
        $query->andFilterWhere(['like', 'name', $this->name])
71
            ->andFilterWhere(['like', 'slug', $this->slug])
72
            ->andFilterWhere(['like', 'singular_name', $this->singular_name])
73
            ->andFilterWhere(['like', 'plural_name', $this->plural_name]);
74
75
        return $dataProvider;
76
    }
77
}
78