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 |
||
5 | class Navigation { |
||
6 | private $last_ordre; |
||
7 | |||
8 | |||
9 | |||
10 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
11 | /** |
||
12 | * Navigation constructor. |
||
13 | * @param null $no_module |
||
14 | * to init get navigation link (if no module != null) whe only get page it's for admin content gestion pages |
||
15 | */ |
||
16 | public function __construct($no_module = null) { |
||
30 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
31 | |||
32 | |||
33 | |||
34 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
35 | /** |
||
36 | * @param $id_page |
||
37 | * @return array |
||
38 | * to get the navigation link of pages of the website |
||
39 | */ |
||
40 | private function getLienNavigationPage($id_page) { |
||
60 | |||
61 | /** |
||
62 | * @param $id_page |
||
63 | * @return array |
||
64 | * to get the sub navigation of a page which have it |
||
65 | */ |
||
66 | private function getSousMenu($id_page) { |
||
87 | |||
88 | /** |
||
89 | * @param $id_module |
||
90 | * @return array |
||
91 | * to get the navigation link of modules of the website |
||
92 | */ |
||
93 | private function getLienNavigationModule($id_module) { |
||
112 | |||
113 | /*to verify if page exist*/ |
||
114 | private function getLienPageExist($id_page) { |
||
125 | |||
126 | private function getLienPage($url) { |
||
134 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
135 | |||
136 | |||
137 | |||
138 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
139 | /** |
||
140 | * @param $query |
||
141 | * function that create navigation called in construct |
||
142 | */ |
||
143 | private function setNavigation($query) { |
||
161 | |||
162 | |||
163 | /** |
||
164 | * @param $id |
||
165 | * @param $value_id |
||
166 | * to add a link in navigation table |
||
167 | */ |
||
168 | public function setAjoutLien($id, $value_id) { |
||
175 | |||
176 | /** |
||
177 | * @param $id |
||
178 | * @param $value_id |
||
179 | * to delete a link in navigation table |
||
180 | */ |
||
181 | public function setSupprimerLien($id, $value_id) { |
||
186 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
187 | } |
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.