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 |
||
28 | View Code Duplication | class DeleteDocumentResponse extends Response |
|
|
|||
29 | { |
||
30 | |||
31 | const PROP_OK = 'ok'; |
||
32 | const PROP_FOUND = 'found'; |
||
33 | const PROP_ID = '_id'; |
||
34 | const PROP_VERSION = '_version'; |
||
35 | const PROP_INDEX = '_index'; |
||
36 | const PROP_TYPE = '_type'; |
||
37 | |||
38 | /** |
||
39 | * Getter Method |
||
40 | * |
||
41 | * @return mixed |
||
42 | * @author Daniel Wendlandt |
||
43 | */ |
||
44 | 2 | public function isOk() |
|
50 | |||
51 | /** |
||
52 | * Getter Method |
||
53 | * |
||
54 | * @return mixed |
||
55 | * @author Daniel Wendlandt |
||
56 | */ |
||
57 | 2 | public function found() |
|
63 | |||
64 | /** |
||
65 | * Getter Method |
||
66 | * |
||
67 | * @return mixed |
||
68 | * @author Daniel Wendlandt |
||
69 | */ |
||
70 | 2 | public function getId() |
|
76 | |||
77 | /** |
||
78 | * Getter Method |
||
79 | * |
||
80 | * @return mixed |
||
81 | * @author Daniel Wendlandt |
||
82 | */ |
||
83 | 2 | public function getVersion() |
|
89 | |||
90 | /** |
||
91 | * Getter Method |
||
92 | * |
||
93 | * @return mixed |
||
94 | * @author Daniel Wendlandt |
||
95 | */ |
||
96 | 2 | public function getIndex() |
|
102 | |||
103 | /** |
||
104 | * Getter Method |
||
105 | * |
||
106 | * @return mixed |
||
107 | * @author Daniel Wendlandt |
||
108 | */ |
||
109 | 12 | public function getType() |
|
115 | } |
||
116 |
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.