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 AdminComment extends Comment { |
||
8 | private $values = []; |
||
9 | |||
10 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
11 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
12 | |||
13 | |||
14 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
15 | /** |
||
16 | * @return array |
||
17 | * function to get values out of the class |
||
18 | */ |
||
19 | public function getValues(){ |
||
22 | |||
23 | /** |
||
24 | * function that get a list of all table_name wich are in comment module |
||
25 | */ |
||
26 | public function getAllTable() { |
||
45 | |||
46 | /** |
||
47 | * @param $table |
||
48 | * @param $id_in_table |
||
49 | * function to get all comments of a table with an id |
||
50 | */ |
||
51 | public function getAllComment($table, $id_in_table) { |
||
71 | |||
72 | /** |
||
73 | * @param $table_name |
||
74 | * @param $checked |
||
75 | * @return int |
||
76 | * function that get number of checked or unchecked comment for a table_name |
||
77 | */ |
||
78 | private function getNbCheckedComment($table_name, $checked) { |
||
86 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
87 | |||
88 | |||
89 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
90 | /** |
||
91 | * @param $values |
||
92 | * function to set all values and sort it in future |
||
93 | */ |
||
94 | public function setValues($values) { |
||
97 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
98 | } |
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.