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 |
||
7 | class DBStaticChat { |
||
8 | |||
9 | // Chat ************************************************************************************************************* |
||
10 | public static function db_chat_player_list_online($chat_refresh_rate, $ally_add) { |
||
23 | |||
24 | /** |
||
25 | * @param $user_id |
||
26 | * @param $nickUnsafe |
||
27 | * @param $ally_id |
||
28 | * @param $message_unsafe |
||
29 | * @param $chat_message_sender_name_unsafe |
||
30 | * @param $chat_message_recipient_id |
||
31 | * @param $chat_message_recipient_name_unsafe |
||
32 | */ |
||
33 | View Code Duplication | public static function db_chat_message_insert($user_id, $nickUnsafe, $ally_id, $message_unsafe, $chat_message_sender_name_unsafe = '', $chat_message_recipient_id = 0, $chat_message_recipient_name_unsafe = '') { |
|
45 | |||
46 | /** |
||
47 | * @param $alliance |
||
48 | * |
||
49 | * @return array|bool|mysqli_result|null |
||
50 | */ |
||
51 | public static function db_chat_message_count_by_ally($alliance) { |
||
56 | |||
57 | /** |
||
58 | * @param $alliance |
||
59 | * @param $where_add |
||
60 | * @param $start_row |
||
61 | * @param $page_limit |
||
62 | * |
||
63 | * @return array|bool|mysqli_result|null |
||
64 | */ |
||
65 | public static function db_chat_message_get_page($alliance, $where_add, $start_row, $page_limit) { |
||
75 | |||
76 | /** |
||
77 | * @param $chat_directive |
||
78 | * @param $userId |
||
79 | */ |
||
80 | public static function db_chat_player_update_invisibility($chat_directive, $userId) { |
||
91 | |||
92 | /** |
||
93 | * @param $reasonUnsafe |
||
94 | * @param $chat_player_subject_id |
||
95 | */ |
||
96 | View Code Duplication | public static function db_chat_player_update_unmute($reasonUnsafe, $chat_player_subject_id) { |
|
108 | |||
109 | /** |
||
110 | * @param $date_compiled |
||
111 | * @param $reasonUnsafe |
||
112 | * @param $chat_player_subject_id |
||
113 | */ |
||
114 | View Code Duplication | public static function db_chat_player_update_mute($date_compiled, $reasonUnsafe, $chat_player_subject_id) { |
|
126 | |||
127 | /** |
||
128 | * @param $delete |
||
129 | */ |
||
130 | public static function db_chat_message_delete($delete) { |
||
138 | |||
139 | public static function db_chat_message_purge() { |
||
142 | |||
143 | /** |
||
144 | * @return array|bool|mysqli_result|null |
||
145 | */ |
||
146 | public static function db_chat_message_get_last_25() { |
||
151 | |||
152 | |||
153 | /** |
||
154 | * @param $player_id |
||
155 | * @param $fields |
||
156 | * |
||
157 | * @return array|bool|mysqli_result|null |
||
158 | */ |
||
159 | public static function db_chat_player_get($player_id, $fields) { |
||
162 | |||
163 | |||
164 | /** |
||
165 | * @param $player_id |
||
166 | */ |
||
167 | public static function db_chat_player_insert($player_id) { |
||
172 | |||
173 | |||
174 | /** |
||
175 | * @param $userId |
||
176 | */ |
||
177 | public static function db_chat_player_update($userId) { |
||
188 | |||
189 | |||
190 | /** |
||
191 | * @param $alliance |
||
192 | * @param $user |
||
193 | * |
||
194 | * @return array|bool|mysqli_result|null |
||
195 | */ |
||
196 | public static function db_chat_list_select_advanced($alliance, $user) { |
||
210 | |||
211 | |||
212 | /** |
||
213 | * @param $alliance |
||
214 | * @param $user |
||
215 | * @param $where_add |
||
216 | * @param $start_row |
||
217 | * @param $page_limit |
||
218 | * |
||
219 | * @return array|bool|mysqli_result|null |
||
220 | */ |
||
221 | public static function db_chat_list_get_with_users($alliance, $user, $where_add, $start_row, $page_limit) { |
||
240 | |||
241 | /** |
||
242 | * @param $user |
||
243 | * |
||
244 | * @return array|bool|mysqli_result|null |
||
245 | */ |
||
246 | public static function db_chat_player_select_id($user) { |
||
251 | |||
252 | |||
253 | /** |
||
254 | * @param $userId |
||
255 | */ |
||
256 | public static function db_chat_player_update_activity($userId) { |
||
267 | |||
268 | } |
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.