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 NodeInfoResponse extends Response |
|
|
|||
29 | { |
||
30 | |||
31 | const PROP_OK = 'ok'; |
||
32 | const PROP_STATUS = 'status'; |
||
33 | const PROP_NAME = 'name'; |
||
34 | const PROP_VERSION = 'version'; |
||
35 | const PROP_TAGLINE = 'tagline'; |
||
36 | |||
37 | /** |
||
38 | * Getter Method |
||
39 | * |
||
40 | * @return mixed |
||
41 | * @author Daniel Wendlandt |
||
42 | */ |
||
43 | 2 | public function isOk() |
|
49 | |||
50 | /** |
||
51 | * Getter Method |
||
52 | * |
||
53 | * @return mixed |
||
54 | * @author Daniel Wendlandt |
||
55 | */ |
||
56 | 2 | public function getVersion() |
|
62 | |||
63 | /** |
||
64 | * Getter Method |
||
65 | * |
||
66 | * @return mixed |
||
67 | * @author Daniel Wendlandt |
||
68 | */ |
||
69 | 2 | public function getName() |
|
75 | |||
76 | /** |
||
77 | * Getter Method |
||
78 | * |
||
79 | * @return mixed |
||
80 | * @author Daniel Wendlandt |
||
81 | */ |
||
82 | 2 | public function getStatus() |
|
88 | |||
89 | /** |
||
90 | * Getter Method |
||
91 | * |
||
92 | * @return mixed |
||
93 | * @author Daniel Wendlandt |
||
94 | */ |
||
95 | 2 | public function getTagline() |
|
101 | |||
102 | } |
||
103 |
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.