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 Subscription implements RouteInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | Root |
||
26 | */ |
||
27 | public static function root() |
||
31 | /* |
||
32 | Create subscription |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * create |
||
37 | * Insert description here |
||
38 | * |
||
39 | * @return |
||
40 | * |
||
41 | * @access |
||
42 | * @static |
||
43 | * @see |
||
44 | * @since |
||
45 | */ |
||
46 | public static function create() |
||
56 | /* |
||
57 | Get subscription |
||
58 | */ |
||
59 | |||
60 | /** |
||
61 | * fetch |
||
62 | * Insert description here |
||
63 | * |
||
64 | * @return |
||
65 | * |
||
66 | * @access |
||
67 | * @static |
||
68 | * @see |
||
69 | * @since |
||
70 | */ |
||
71 | public static function fetch() |
||
77 | |||
78 | /* |
||
79 | List subscription |
||
80 | */ |
||
81 | |||
82 | /** |
||
83 | * getList |
||
84 | * Insert description here |
||
85 | * |
||
86 | * @return |
||
87 | * |
||
88 | * @access |
||
89 | * @static |
||
90 | * @see |
||
91 | * @since |
||
92 | */ |
||
93 | public static function getList() |
||
98 | /* |
||
99 | Disable subscription |
||
100 | */ |
||
101 | |||
102 | /** |
||
103 | * disable |
||
104 | * Insert description here |
||
105 | * |
||
106 | * @return |
||
107 | * |
||
108 | * @access |
||
109 | * @static |
||
110 | * @see |
||
111 | * @since |
||
112 | */ |
||
113 | View Code Duplication | public static function disable() |
|
121 | |||
122 | /* |
||
123 | Enable subscription |
||
124 | */ |
||
125 | |||
126 | /** |
||
127 | * enable |
||
128 | * Insert description here |
||
129 | * |
||
130 | * @return |
||
131 | * |
||
132 | * @access |
||
133 | * @static |
||
134 | * @see |
||
135 | * @since |
||
136 | */ |
||
137 | View Code Duplication | public static function enable() |
|
145 | } |
||
146 |
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.