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 |
||
32 | class Taxonomy extends ActiveRecord |
||
33 | { |
||
34 | const HIERARCHICAL = 1; |
||
35 | const NOT_HIERARCHICAL = 0; |
||
36 | const MENU_BUILDER = 1; |
||
37 | const NOT_MENU_BUILDER = 0; |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | public static function tableName() |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | View Code Duplication | public function behaviors() |
|
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | public function rules() |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | View Code Duplication | public function attributeLabels() |
|
94 | |||
95 | /** |
||
96 | * @return \yii\db\ActiveQuery |
||
97 | */ |
||
98 | public function getPostTypeTaxonomies() |
||
102 | |||
103 | /** |
||
104 | * @return \yii\db\ActiveQuery |
||
105 | */ |
||
106 | public function getPostTypes() |
||
111 | |||
112 | /** |
||
113 | * @return \yii\db\ActiveQuery |
||
114 | */ |
||
115 | public function getTerms() |
||
119 | |||
120 | /** |
||
121 | * Get array of taxonomy hierarchical for label or dropdown. |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | View Code Duplication | public function getHierarchies() |
|
132 | |||
133 | /** |
||
134 | * Get array of menu_builder hierarchical for label or dropdown. |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | View Code Duplication | public function getMenuBuilders() |
|
145 | } |
||
146 |
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.