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 |
||
23 | class Screen extends \yii\db\ActiveRecord |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | public static function tableName() |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | View Code Duplication | public function rules() |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function attributeLabels() |
||
62 | |||
63 | /** |
||
64 | * Loop through parent flows to build a flows tree. |
||
65 | * |
||
66 | * @return array flows with all parents |
||
67 | */ |
||
68 | public function allFlows() |
||
93 | |||
94 | /** |
||
95 | * Update last_modified field to force screen reload. |
||
96 | */ |
||
97 | public function setModified() |
||
102 | |||
103 | /** |
||
104 | * @return \yii\db\ActiveQuery |
||
105 | */ |
||
106 | public function getDeviceHasScreens() |
||
110 | |||
111 | /** |
||
112 | * @return \yii\db\ActiveQuery |
||
113 | */ |
||
114 | public function getDevices() |
||
118 | |||
119 | /** |
||
120 | * @return \yii\db\ActiveQuery |
||
121 | */ |
||
122 | public function getTemplate() |
||
126 | |||
127 | /** |
||
128 | * @return \yii\db\ActiveQuery |
||
129 | */ |
||
130 | public function getScreenHasFlows() |
||
134 | |||
135 | /** |
||
136 | * @return \yii\db\ActiveQuery |
||
137 | */ |
||
138 | public function getFlows() |
||
142 | } |
||
143 |
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.