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 |
||
8 | class DBStaticNote { |
||
9 | |||
10 | public static function db_note_get_id_and_owner($note_id_edit) { |
||
13 | |||
14 | /** |
||
15 | * @param $user_id |
||
16 | * @param bool $sticky |
||
17 | * |
||
18 | * @return array|bool|mysqli_result|null |
||
19 | */ |
||
20 | public static function db_note_list_by_owner($user_id, $sticky = false) { |
||
27 | |||
28 | /** |
||
29 | * @param $note_priority |
||
30 | * @param $note_title_unsafe |
||
31 | * @param $note_text_unsafe |
||
32 | * @param $note_galaxy |
||
33 | * @param $note_system |
||
34 | * @param $note_planet |
||
35 | * @param $note_planet_type |
||
36 | * @param $note_sticky |
||
37 | * @param $note_id_edit |
||
38 | */ |
||
39 | public static function db_note_update_by_id($note_priority, $note_title_unsafe, $note_text_unsafe, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit) { |
||
58 | |||
59 | /** |
||
60 | * @param $userId |
||
61 | * @param $note_priority |
||
62 | * @param $note_title_unsafe |
||
63 | * @param $note_text_unsafe |
||
64 | * @param $note_galaxy |
||
65 | * @param $note_system |
||
66 | * @param $note_planet |
||
67 | * @param $note_planet_type |
||
68 | * @param $note_sticky |
||
69 | */ |
||
70 | View Code Duplication | public static function db_note_insert( |
|
85 | |||
86 | |||
87 | /** |
||
88 | * @param $user |
||
89 | * |
||
90 | * @return array|bool|mysqli_result|null |
||
91 | */ |
||
92 | public static function db_note_list_select_by_owner_and_planet($user) { |
||
97 | |||
98 | /** |
||
99 | * @param array $user |
||
100 | * @param int $note_id_edit |
||
101 | * |
||
102 | * @throws Exception |
||
103 | */ |
||
104 | public static function processDelete($user, $note_id_edit) { |
||
152 | |||
153 | } |
||
154 |
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.