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 ForumFaction extends Faction { |
||
10 | |||
11 | |||
12 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
13 | public function __construct() { |
||
16 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
17 | |||
18 | |||
19 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
20 | /** |
||
21 | * fonction qui récupère les forums de la faction |
||
22 | */ |
||
23 | public function getListeForum() { |
||
44 | |||
45 | /** |
||
46 | * @param $titre |
||
47 | * @return bool |
||
48 | * fonction qui test si un forum aec ce titre existe déjà |
||
49 | */ |
||
50 | View Code Duplication | private function getForumExist($titre) { |
|
64 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
65 | |||
66 | |||
67 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
68 | /** |
||
69 | * @param $titre |
||
70 | * @param $texte |
||
71 | * @return bool |
||
72 | */ |
||
73 | public function setCreerForum($titre, $texte) { |
||
96 | |||
97 | /** |
||
98 | * @param $url |
||
99 | * fonction qui supprime un forum |
||
100 | */ |
||
101 | public function setSupprimerForum($id_forum) { |
||
107 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
108 | } |
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.