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 |
||
9 | class PermissionsFaction { |
||
10 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
11 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
12 | |||
13 | |||
14 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
15 | /** |
||
16 | * @param $id_identite |
||
17 | * @param $id_faction |
||
18 | * @return bool |
||
19 | * permet de savoir si le joueur en question est le chef de la faction |
||
20 | */ |
||
21 | View Code Duplication | protected function getTestChefFaction($id_identite, $id_faction) { |
|
1 ignored issue
–
show
|
|||
22 | $dbc = App::getDb(); |
||
23 | |||
24 | $query = $dbc->select("ID_identite")->from("_bataille_faction") |
||
25 | ->where("ID_identite", "=", $id_identite, "AND") |
||
26 | ->where("ID_faction", "=", $id_faction) |
||
27 | ->get(); |
||
28 | |||
29 | if (count($query) > 0) { |
||
30 | return true; |
||
31 | } |
||
32 | |||
33 | return false; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return int |
||
38 | * fonction qui renvoi le nombre de permissions |
||
39 | */ |
||
40 | private function getNombrePermissions() { |
||
47 | |||
48 | /** |
||
49 | * @return array |
||
50 | * fonction qui liste toutes les permissions |
||
51 | */ |
||
52 | public function getListePermissions() { |
||
67 | |||
68 | /** |
||
69 | * @param $id_identite |
||
70 | * @param $id_faction |
||
71 | * @return array|string |
||
72 | * permet de récupérer les permissions d'un membre de la faction |
||
73 | */ |
||
74 | protected function getMembrePermissions($id_identite, $id_faction) { |
||
106 | |||
107 | /** |
||
108 | * @param $id_faction |
||
109 | * @return bool |
||
110 | * fonction qui renvoi les permission du membre connecté |
||
111 | */ |
||
112 | public function getPermissionsMembre($id_faction) { |
||
138 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
139 | |||
140 | |||
141 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
142 | /** |
||
143 | * @param $id_permission |
||
144 | * @param $id_identite |
||
145 | * @param $id_faction |
||
146 | * @param $type |
||
147 | * cette fonction permet d'ajouter ou de supprimer un permission à un joueur |
||
148 | */ |
||
149 | public function setGererPermission($id_permission, $id_identite, $id_faction, $type) { |
||
179 | |||
180 | /** |
||
181 | * @param $id_identite |
||
182 | * fonction qui va supprimer tous les droits d'accès du user |
||
183 | */ |
||
184 | protected function setSupprilerAllPermissions($id_identite) { |
||
189 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
190 | } |
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.