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() { |
||
77 | |||
78 | //initialisation of Map class |
||
79 | public static function getMap() { |
||
86 | |||
87 | //initialisation of Batiment class |
||
88 | public static function getUnite() { |
||
95 | |||
96 | //initialisation of CentreRecherche class |
||
97 | public static function getCentreRecherche() { |
||
104 | |||
105 | //initialisation of MissionsAleatoire class |
||
106 | public static function getMissionsAleatoire() { |
||
113 | |||
114 | //initialisation of Nourriture class |
||
115 | public static function getNourriture() { |
||
122 | |||
123 | //initialisation of Database Core connexion |
||
124 | public static function getDb() { |
||
132 | |||
133 | /** |
||
134 | * @return mixe |
||
135 | * récupère l'ID_identité du joueur |
||
136 | */ |
||
137 | public static function getIdIdentite() { |
||
140 | |||
141 | /** |
||
142 | * @return mixed |
||
143 | * renvoi l'id_base du joueur |
||
144 | */ |
||
145 | public static function getIdBase() { |
||
154 | |||
155 | /** |
||
156 | * @return mixed |
||
157 | * renvoi le premier ID_base du joueur (première base et base princ du joueur) |
||
158 | */ |
||
159 | public static function getFirstBase() { |
||
172 | |||
173 | /** |
||
174 | * @param $id_base |
||
175 | * @return array |
||
176 | * fonction qui renvoi les posisitons en x et y d'une base |
||
177 | */ |
||
178 | private static function getPosistionBase($id_base) { |
||
197 | |||
198 | /** |
||
199 | * @return int |
||
200 | * return now timestamp |
||
201 | */ |
||
202 | public static function getToday() { |
||
206 | |||
207 | /** |
||
208 | * @param null $id_base -> sert si definit a recuperer l'id identite de la abse en question |
||
209 | * @return string|null |
||
210 | * recupere la date de la derniere connexion |
||
211 | */ |
||
212 | public static function getLastConnexion($id_base = null) { |
||
234 | |||
235 | /** |
||
236 | * @param string $nom_ressource |
||
237 | * @param $ressource |
||
238 | * @return array |
||
239 | * fonction qui permet de renvyer la couleur rouge si pas assez de ressource pour construire le batiment |
||
240 | * ou pour creer une unité... |
||
241 | */ |
||
242 | public static function getTestAssezRessourceBase($nom_ressource, $ressource) { |
||
257 | |||
258 | /** |
||
259 | * @param $id_base |
||
260 | * @param integer $vitesse = vitesse de l'unité en question |
||
261 | * @return number |
||
262 | * fonction qui renvoi le temps de trajet entre la base du joueur et une autre base en secondes |
||
263 | */ |
||
264 | public static function getDureeTrajet($id_base, $vitesse = 1) { |
||
278 | |||
279 | /** |
||
280 | * @param null $id_identite |
||
281 | * get nation of a player |
||
282 | */ |
||
283 | public static function getNation($id_identite = null) { |
||
303 | |||
304 | /** |
||
305 | * @param $posx |
||
306 | * @param $posy |
||
307 | * @return int |
||
308 | * fonction qui renvoi un ID_base en fonction de sa posx et posy et 0 si base inexistante |
||
309 | */ |
||
310 | public static function getBaseExistPosition($posx, $posy) { |
||
324 | |||
325 | /** |
||
326 | * @return integer |
||
327 | * fonction qui permet de récupérer le nombre de joueurs sur le serveur |
||
328 | */ |
||
329 | public static function getNombreJoueur() { |
||
340 | |||
341 | /** |
||
342 | * @param string $param |
||
343 | * @return mixed |
||
344 | * fonction qui sert à récupérer un parametre spécifique pour un batiment |
||
345 | * par exemple la vitesse d'un marchand ou le nombred'emplacment de la base |
||
346 | */ |
||
347 | public static function getParam($param) { |
||
356 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
357 | |||
358 | |||
359 | |||
360 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
361 | /** |
||
362 | * set la date de derniere connexion a now |
||
363 | */ |
||
364 | public static function setLastConnexion($id_base = null) { |
||
380 | |||
381 | /** |
||
382 | * @param $values |
||
383 | * can set values while keep older infos |
||
384 | */ |
||
385 | public static function setValues($values) { |
||
388 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
389 | } |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.