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 |
||
21 | class Issue extends FormAbstract |
||
22 | { |
||
23 | /** |
||
24 | * An instance of project model. |
||
25 | * |
||
26 | * @var Model\Project |
||
27 | */ |
||
28 | protected $project; |
||
29 | |||
30 | /** |
||
31 | * @param array $params |
||
32 | * |
||
33 | * @return void |
||
34 | */ |
||
35 | 6 | public function setup(array $params) |
|
42 | |||
43 | /** |
||
44 | * @return array |
||
45 | */ |
||
46 | 6 | public function actions() |
|
52 | |||
53 | /** |
||
54 | * @return array |
||
55 | */ |
||
56 | 6 | public function fields() |
|
81 | |||
82 | /** |
||
83 | * Returns title field. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 7 | protected function fieldTitle() |
|
96 | |||
97 | /** |
||
98 | * Returns body field. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | 7 | protected function fieldBody() |
|
111 | |||
112 | /** |
||
113 | * Returns tags field. |
||
114 | * |
||
115 | * @return array |
||
116 | */ |
||
117 | 7 | protected function fieldTags() |
|
144 | |||
145 | /** |
||
146 | * Returns assigned to field. |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | 6 | protected function fieldAssignedTo() |
|
161 | |||
162 | /** |
||
163 | * Returns upload field. |
||
164 | * |
||
165 | * @return array |
||
166 | */ |
||
167 | 6 | protected function fieldUpload() |
|
175 | |||
176 | /** |
||
177 | * Returns time quote field. |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | 6 | protected function fieldTimeQuote() |
|
205 | |||
206 | /** |
||
207 | * @return array |
||
208 | */ |
||
209 | 7 | public function rules() |
|
218 | |||
219 | /** |
||
220 | * @return string |
||
221 | */ |
||
222 | public function getRedirectUrl() |
||
230 | |||
231 | /** |
||
232 | * Extract number of hours, or minutes, or seconds from a quote. |
||
233 | * |
||
234 | * @param string $part |
||
235 | * |
||
236 | * @return float|int |
||
237 | */ |
||
238 | 6 | protected function extractQuoteValue($part) |
|
253 | } |
||
254 |
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.