Complex classes like GestionModule 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 GestionModule, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class GestionModule { |
||
| 6 | private $id_module; |
||
| 7 | private $url; |
||
| 8 | private $nom; |
||
| 9 | private $version; |
||
| 10 | private $online_version; |
||
| 11 | private $icone; |
||
| 12 | private $url_telechargement; |
||
| 13 | |||
| 14 | |||
| 15 | //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------// |
||
| 16 | //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------// |
||
| 17 | |||
| 18 | |||
| 19 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
| 20 | public function getIdModule() { |
||
| 21 | return $this->id_module; |
||
| 22 | } |
||
| 23 | public function getUrl() { |
||
| 24 | return $this->url; |
||
| 25 | } |
||
| 26 | public function getNom() { |
||
| 27 | return $this->nom; |
||
| 28 | } |
||
| 29 | public function getVersion() { |
||
| 35 | public function getIcone() { |
||
| 36 | return $this->icone; |
||
| 37 | } |
||
| 38 | public function getUrlTelechargement() { |
||
| 39 | return $this->url_telechargement; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * récupere la liste des modules activé utilisé pour toutes les pages |
||
| 44 | */ |
||
| 45 | public function getListeModuleActiver() { |
||
| 68 | |||
| 69 | /** |
||
| 70 | * recupere la listes des modules ajouter par un autre admin |
||
| 71 | * fonction utilisée uniquement dans la config |
||
| 72 | */ |
||
| 73 | public function getListeModule() { |
||
| 96 | |||
| 97 | /** |
||
| 98 | * recupere la listes des modules systeme |
||
| 99 | * fonction utilisée uniquement dans la config |
||
| 100 | */ |
||
| 101 | public function getListeModuleSysteme() { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param $nom_module |
||
| 127 | * @return bool |
||
| 128 | * permets de savoir si un module est installé ou non |
||
| 129 | */ |
||
| 130 | public static function getModuleInstaller($nom_module) { |
||
| 131 | $dbc = App::getDb(); |
||
| 132 | |||
| 133 | $query = $dbc->query("SELECT * FROM module WHERE nom_module = ".$dbc->quote($nom_module)); |
||
| 134 | |||
| 135 | if ((is_array($query)) && (count($query) > 0)) { |
||
| 136 | $installer = 0; |
||
| 137 | |||
| 138 | foreach ($query as $obj) { |
||
| 139 | $installer = $obj->installer; |
||
| 140 | } |
||
| 141 | |||
| 142 | return $installer; |
||
| 143 | } |
||
| 144 | else { |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param $nom_module |
||
| 151 | * @return boolean|null |
||
| 152 | * return true si le module est activer sinon false |
||
| 153 | */ |
||
| 154 | public static function getModuleActiver($nom_module) { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param $nom_module |
||
| 173 | * @return boolean|null |
||
| 174 | * fonction qui permet de savoir si un module est à jour ou non |
||
| 175 | * si a jour renvoi true sinon renvoi false |
||
| 176 | */ |
||
| 177 | public static function getModuleAJour($nom_module) { |
||
| 193 | |||
| 194 | /** |
||
| 195 | * fonction qui se lance à chaquer fois que l'on ouvre l'admin |
||
| 196 | * permet de tester si tous les modules présent sur le site sont bien à jour |
||
| 197 | */ |
||
| 198 | public function getCheckModuleVersion() { |
||
| 267 | |||
| 268 | public function getListeModuleMettreJour() { |
||
| 292 | //-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
||
| 293 | |||
| 294 | |||
| 295 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
| 296 | private function setListeModuleActiver($id_module, $url, $version, $nom, $icone = null, $url_telechargement = null) { |
||
| 304 | |||
| 305 | private function setListeModuleMettreJour($nom_module, $version, $online_version) { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @param $activer |
||
| 313 | * @param $url |
||
| 314 | * fonction qui permet d'activer || désactiver un module |
||
| 315 | */ |
||
| 316 | public static function setActiverDesactiverModule($activer, $url) { |
||
| 326 | //-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
||
| 327 | } |
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.