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:
Complex classes like GestionDroitAcces often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GestionDroitAcces, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class GestionDroitAcces extends DroitAcces { |
||
| 7 | //pour les droit_acces standard |
||
| 8 | private $id_liste_droit_acces; |
||
|
|
|||
| 9 | private $nom_liste; |
||
| 10 | private $droit_acces; |
||
| 11 | private $nb_droit_acces; |
||
| 12 | |||
| 13 | //pour les droits d'acces sur les page |
||
| 14 | private $id_page; |
||
| 15 | private $titre_page; |
||
| 16 | private $nb_droit_acces_page; |
||
| 17 | |||
| 18 | //pour la table identite |
||
| 19 | private $id_identite; |
||
| 20 | private $pseudo; |
||
| 21 | private $nom; |
||
| 22 | private $prenom; |
||
| 23 | private $nb_user; |
||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------// |
||
| 28 | public function __construct($id_liste_droit_acces = null) { |
||
| 36 | //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------// |
||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
| 41 | //pour les droit_acces standard |
||
| 42 | public function getIdListeDroitAcces() { |
||
| 54 | |||
| 55 | //pour les droits d'acces sur les page |
||
| 56 | public function getIdPage() { |
||
| 65 | |||
| 66 | //pour la table identite |
||
| 67 | public function getIdidentite() { |
||
| 82 | |||
| 83 | /** |
||
| 84 | * appellee dans le constructeur pour afficher les listes de droit d'acces |
||
| 85 | */ |
||
| 86 | private function getListeDroitAcces() { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @param $id_liste_droit_acces |
||
| 120 | * @return integer |
||
| 121 | */ |
||
| 122 | private function getNombreUtilisateurListe($id_liste_droit_acces) { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param $id_liste_droit_acces |
||
| 139 | * @return integer |
||
| 140 | */ |
||
| 141 | private function getNombreDroitAccesListe($id_liste_droit_acces) { |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param $id_liste_droit_acces |
||
| 158 | * @return integer |
||
| 159 | */ |
||
| 160 | private function getNombrePageListe($id_liste_droit_acces) { |
||
| 174 | |||
| 175 | /** |
||
| 176 | * fonction qui récupère la liste des droits d'acces en texte en fonction de l'id de la liste |
||
| 177 | * @param $id_liste_droit_acces |
||
| 178 | */ |
||
| 179 | View Code Duplication | public function getListeDroitAccesDetailDroit() { |
|
| 195 | |||
| 196 | /** |
||
| 197 | * fonction qui récupère la liste des utilisateur dans une liste de droits d'acces en texte en fonction de l'id de la liste |
||
| 198 | * @param $id_liste_droit_acces |
||
| 199 | */ |
||
| 200 | public function getListeDroitAccesDetailUser() { |
||
| 221 | |||
| 222 | /** |
||
| 223 | * fonction qui récupère la liste des droits d'acces sur les pages en texte en fonction de l'id de la liste |
||
| 224 | * @param $id_liste_droit_acces |
||
| 225 | */ |
||
| 226 | public function getListeDroitAccesDetailPage() { |
||
| 247 | //-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
||
| 248 | |||
| 249 | |||
| 250 | |||
| 251 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
| 252 | private function setListeDroitAcces($id_liste_droit_acces, $nom_liste, $nb_droit_acces, $nb_droit_acces_page, $nb_user) { |
||
| 272 | //-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
||
| 273 | } |