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 |
||
17 | class ConversationDB extends DB |
||
18 | { |
||
19 | /** |
||
20 | * Initilize conversation table |
||
21 | */ |
||
22 | 9 | public static function initializeConversation() |
|
28 | |||
29 | /** |
||
30 | * Select a conversation from the DB |
||
31 | * |
||
32 | * @param int $user_id |
||
33 | * @param int $chat_id |
||
34 | * @param bool $limit |
||
35 | * |
||
36 | * @return array|bool |
||
37 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
38 | */ |
||
39 | 9 | public static function selectConversation($user_id, $chat_id, $limit = null) |
|
69 | |||
70 | /** |
||
71 | * Insert the conversation in the database |
||
72 | * |
||
73 | * @param int $user_id |
||
74 | * @param int $chat_id |
||
75 | * @param string $command |
||
76 | * |
||
77 | * @return bool |
||
78 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
79 | */ |
||
80 | public static function insertConversation($user_id, $chat_id, $command) |
||
113 | |||
114 | /** |
||
115 | * Update a specific conversation |
||
116 | * |
||
117 | * @param array $fields_values |
||
118 | * @param array $where_fields_values |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public static function updateConversation(array $fields_values, array $where_fields_values) |
||
126 | |||
127 | /** |
||
128 | * Update the conversation in the database |
||
129 | * |
||
130 | * @param string $table |
||
131 | * @param array $fields_values |
||
132 | * @param array $where_fields_values |
||
133 | * |
||
134 | * @todo This function is generic should be moved in DB.php |
||
135 | * |
||
136 | * @return bool |
||
137 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
138 | */ |
||
139 | public static function update($table, array $fields_values, array $where_fields_values) |
||
186 | } |
||
187 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.