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 |
||
32 | class renderer { |
||
33 | |||
34 | private $settings; |
||
35 | |||
36 | public function __construct(&$settings) { |
||
39 | |||
40 | /** |
||
41 | * @return |
||
42 | */ |
||
43 | public function render_group_header($name, $itemname = null, $itemdescription = null) { |
||
53 | |||
54 | /** |
||
55 | * @return |
||
56 | */ |
||
57 | public function render_group_element($name, $item) { |
||
63 | |||
64 | /** |
||
65 | * @return Object |
||
66 | */ |
||
67 | View Code Duplication | public function& render_group_element_text($name, $default = null, $type = PARAM_RAW) { |
|
74 | |||
75 | /** |
||
76 | * @return Object |
||
77 | */ |
||
78 | View Code Duplication | public function& render_group_element_checkbox($name, $default = null) { |
|
85 | |||
86 | /** |
||
87 | * @return Object |
||
88 | */ |
||
89 | View Code Duplication | public function& render_group_element_configmultiselect($name, $defaultsetting, $choices) { |
|
96 | |||
97 | /** |
||
98 | * @return boolean |
||
99 | */ |
||
100 | public static function section_general_shown() { |
||
105 | |||
106 | /** |
||
107 | * @return boolean |
||
108 | */ |
||
109 | public static function section_record_meeting_shown() { |
||
115 | |||
116 | /** |
||
117 | * @return boolean |
||
118 | */ |
||
119 | public static function section_import_recordings_shown() { |
||
125 | |||
126 | /** |
||
127 | * @return boolean |
||
128 | */ |
||
129 | public static function section_show_recordings_shown() { |
||
138 | |||
139 | /** |
||
140 | * @return boolean |
||
141 | */ |
||
142 | public static function section_wait_moderator_shown() { |
||
149 | |||
150 | /** |
||
151 | * @return boolean |
||
152 | */ |
||
153 | public static function section_static_voice_bridge_shown() { |
||
157 | |||
158 | /** |
||
159 | * @return boolean |
||
160 | */ |
||
161 | public static function section_preupload_presentation_shown() { |
||
165 | |||
166 | /** |
||
167 | * @return boolean |
||
168 | */ |
||
169 | public static function section_user_limit_shown() { |
||
174 | |||
175 | /** |
||
176 | * @return boolean |
||
177 | */ |
||
178 | public static function section_scheduled_duration_shown() { |
||
182 | |||
183 | /** |
||
184 | * @return boolean |
||
185 | */ |
||
186 | public static function section_moderator_default_shown() { |
||
190 | |||
191 | /** |
||
192 | * @return boolean |
||
193 | */ |
||
194 | public static function section_send_notifications_shown() { |
||
198 | |||
199 | /** |
||
200 | * @return boolean |
||
201 | */ |
||
202 | public static function section_settings_extended_shown() { |
||
207 | } |
||
208 |
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.