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 |
||
5 | class Suggestions extends Response |
||
6 | { |
||
7 | /** |
||
8 | * Iterates over the suggestions |
||
9 | * |
||
10 | * @return \ArrayIterator |
||
11 | */ |
||
12 | public function getIterator() |
||
16 | |||
17 | /** |
||
18 | * @return array |
||
19 | */ |
||
20 | View Code Duplication | public function suggestions() |
|
28 | |||
29 | /** |
||
30 | * @return int |
||
31 | */ |
||
32 | View Code Duplication | public function numFound() |
|
40 | |||
41 | /** |
||
42 | * @return int |
||
43 | */ |
||
44 | View Code Duplication | public function startOffset() |
|
52 | |||
53 | /** |
||
54 | * @return int |
||
55 | */ |
||
56 | View Code Duplication | public function endOffset() |
|
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | View Code Duplication | public function collation() |
|
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | public function command() |
||
84 | |||
85 | /** |
||
86 | * Returns the "collation", or recommendation. |
||
87 | */ |
||
88 | public function __toString() |
||
92 | } |
||
93 |
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.