Complex classes like Bataille 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 Bataille, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class Bataille { |
||
| 7 | private static $ressource; |
||
| 8 | private static $base; |
||
| 9 | private static $batiment; |
||
| 10 | private static $points; |
||
| 11 | private static $unite; |
||
| 12 | private static $centre_recherche; |
||
| 13 | private static $missions_aleatoire; |
||
| 14 | private static $nourriture; |
||
|
|
|||
| 15 | private static $map; |
||
| 16 | private static $database; |
||
| 17 | private static $nation; |
||
| 18 | |||
| 19 | private static $id_base; |
||
| 20 | |||
| 21 | public static $values = []; |
||
| 22 | |||
| 23 | |||
| 24 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
| 25 | public function __construct() { |
||
| 28 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
| 33 | /** |
||
| 34 | * @return array |
||
| 35 | * get array of all values wich will be used in the page |
||
| 36 | */ |
||
| 37 | public static function getValues() { |
||
| 40 | |||
| 41 | //initilisation of all classes of battle |
||
| 42 | //initialisation of Ressource class |
||
| 43 | public static function getRessource() { |
||
| 50 | |||
| 51 | //initialisation of Base class |
||
| 52 | public static function getBase() { |
||
| 59 | |||
| 60 | //initialisation of Batiment class |
||
| 61 | public static function getBatiment() { |
||
| 68 | |||
| 69 | //initialisation of Points class |
||
| 70 | public static function getPoints($points = null) { |
||
| 77 | |||
| 78 | //initialisation of Batiment class |
||
| 79 | public static function getUnite() { |
||
| 86 | |||
| 87 | //initialisation of CentreRecherche class |
||
| 88 | public static function getCentreRecherche() { |
||
| 95 | |||
| 96 | //initialisation of MissionsAleatoire class |
||
| 97 | public static function getMissionsAleatoire() { |
||
| 104 | |||
| 105 | //initialisation of Database Core connexion |
||
| 106 | public static function getDb() { |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return mixe |
||
| 117 | * récupère l'ID_identité du joueur |
||
| 118 | */ |
||
| 119 | public static function getIdIdentite() { |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @return mixed |
||
| 125 | * renvoi l'id_base du joueur |
||
| 126 | */ |
||
| 127 | public static function getIdBase() { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return mixed |
||
| 139 | * renvoi le premier ID_base du joueur (première base et base princ du joueur) |
||
| 140 | */ |
||
| 141 | public static function getFirstBase() { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param $id_base |
||
| 157 | * @return array |
||
| 158 | * fonction qui renvoi les posisitons en x et y d'une base |
||
| 159 | */ |
||
| 160 | private static function getPosistionBase($id_base) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return int |
||
| 182 | * return now timestamp |
||
| 183 | */ |
||
| 184 | public static function getToday() { |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param string $nom_ressource |
||
| 191 | * @param $ressource |
||
| 192 | * @return array |
||
| 193 | * fonction qui permet de renvyer la couleur rouge si pas assez de ressource pour construire le batiment |
||
| 194 | * ou pour creer une unité... |
||
| 195 | */ |
||
| 196 | public static function getTestAssezRessourceBase($nom_ressource, $ressource) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param $id_base |
||
| 214 | * @param integer $vitesse = vitesse de l'unité en question |
||
| 215 | * @return number |
||
| 216 | * fonction qui renvoi le temps de trajet entre la base du joueur et une autre base en secondes |
||
| 217 | */ |
||
| 218 | public static function getDureeTrajet($id_base, $vitesse = 1) { |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param null $id_identite |
||
| 235 | * get nation of a player |
||
| 236 | */ |
||
| 237 | public static function getNation($id_identite = null) { |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @param $posx |
||
| 260 | * @param $posy |
||
| 261 | * @return int |
||
| 262 | * fonction qui renvoi un ID_base en fonction de sa posx et posy et 0 si base inexistante |
||
| 263 | */ |
||
| 264 | public static function getBaseExistPosition($posx, $posy) { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @param string $param |
||
| 281 | * @return mixed |
||
| 282 | * fonction qui sert à récupérer un parametre spécifique pour un batiment |
||
| 283 | * par exemple la vitesse d'un marchand ou le nombred'emplacment de la base |
||
| 284 | */ |
||
| 285 | public static function getParam($param) { |
||
| 294 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
| 295 | |||
| 296 | |||
| 297 | |||
| 298 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
| 299 | /** |
||
| 300 | * @param $values |
||
| 301 | * can set values while keep older infos |
||
| 302 | */ |
||
| 303 | public static function setValues($values) { |
||
| 306 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
| 307 | } |
This check marks private properties in classes that are never used. Those properties can be removed.