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 BulkResponse extends Response |
|
|
|||
29 | { |
||
30 | const PROP_TOOK = 'took'; |
||
31 | const PROP_ERRORS = 'errors'; |
||
32 | const PROP_ITEMS = 'items'; |
||
33 | |||
34 | const PROP_INDEX = '_index'; |
||
35 | const PROP_TYPE = '_type'; |
||
36 | const PROP_ID = '_id'; |
||
37 | const PROP_VERSION = '_version'; |
||
38 | const PROP_STATUS = 'status'; |
||
39 | |||
40 | /** |
||
41 | * Getter Method |
||
42 | * |
||
43 | * @return mixed |
||
44 | * @author Daniel Wendlandt |
||
45 | */ |
||
46 | 2 | public function took() |
|
52 | |||
53 | /** |
||
54 | * Getter Method |
||
55 | * |
||
56 | * @return bool |
||
57 | * @author Daniel Wendlandt |
||
58 | */ |
||
59 | 2 | public function errors() |
|
65 | |||
66 | /** |
||
67 | * Getter Method |
||
68 | * |
||
69 | * @return mixed |
||
70 | * @author Daniel Wendlandt |
||
71 | */ |
||
72 | 2 | public function getItems() |
|
78 | } |
||
79 |
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.