Complex classes like Commander 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 Commander, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class Commander |
||
18 | { |
||
19 | public $id = 0; |
||
20 | public $name = ''; |
||
21 | public $experience = 0; |
||
22 | public $avatar = ''; |
||
23 | public $rPlayer = 0; |
||
24 | public $rBase = 0; |
||
25 | public $comment = ''; |
||
26 | public $sexe = 0; |
||
27 | public $age = 0; |
||
28 | public $level = 0; |
||
29 | public $uExperience = 0; |
||
30 | public $palmares = 0; |
||
31 | public $statement = Commander::INSCHOOL; |
||
32 | public $line = 1; |
||
33 | public $dCreation = ''; |
||
34 | public $dAffectation = ''; |
||
35 | public $dDeath = ''; |
||
36 | |||
37 | # variables de jointure quelconque |
||
38 | public $oBName = ''; |
||
39 | public $playerName = ''; |
||
40 | public $playerColor = 0; |
||
41 | |||
42 | # variables de combat |
||
43 | public $squadronsIds = array(); |
||
44 | public $armyInBegin = array(); |
||
45 | public $armyAtEnd = array(); |
||
46 | public $pevInBegin = 0; |
||
47 | public $earnedExperience = 0; |
||
48 | public $winner = FALSE; |
||
49 | public $isAttacker = NULL; |
||
50 | |||
51 | # variables de déplacement |
||
52 | public $dStart = ''; |
||
53 | public $dArrival = ''; |
||
54 | public $resources = 0; |
||
55 | public $travelType = 0; |
||
56 | public $travelLength = 0; |
||
57 | public $rStartPlace = 0; |
||
58 | public $rDestinationPlace = 0; |
||
59 | public $startPlaceName = ''; |
||
60 | public $startPlacePop = 0; |
||
61 | public $destinationPlaceName = ''; |
||
62 | public $destinationPlacePop = 0; |
||
63 | # Tableau d'objets squadron |
||
64 | public $army = array(); |
||
65 | |||
66 | public $uCommander = ''; |
||
67 | public $hasToU = TRUE; |
||
68 | public $hasArmySetted = FALSE; |
||
69 | public $uMethodCtced = FALSE; |
||
70 | public $lastUMethod = NULL; |
||
71 | |||
72 | const COEFFSCHOOL = 100; |
||
73 | const COEFFEARNEDEXP = 50; |
||
74 | const COEFFEXPPLAYER = 100; |
||
75 | const CMDBASELVL = 100; |
||
76 | |||
77 | const FLEETSPEED = 35; |
||
78 | |||
79 | const COEFFMOVEINSYSTEM = 584; |
||
80 | const COEFFMOVEOUTOFSYSTEM = 600; |
||
81 | const COEFFMOVEINTERSYSTEM = 50000; |
||
82 | |||
83 | const LVLINCOMECOMMANDER = 200; |
||
84 | |||
85 | const CREDITCOEFFTOCOLONIZE = 80000; |
||
86 | const CREDITCOEFFTOCONQUER = 150000; |
||
87 | |||
88 | # loot const |
||
89 | const LIMITTOLOOT = 5000; |
||
90 | const COEFFLOOT = 275; |
||
91 | |||
92 | # Commander statements |
||
93 | const INSCHOOL = 0; # dans l'école |
||
94 | const AFFECTED = 1; # autour de la base |
||
95 | const MOVING = 2; # en déplacement |
||
96 | const DEAD = 3; # mort |
||
97 | const DESERT = 4; # déserté |
||
98 | const RETIRED = 5; # à la retraite |
||
99 | const ONSALE = 6; # dans le marché |
||
100 | const RESERVE = 7; # dans la réserve (comme à l'école mais n'apprend pas) |
||
101 | |||
102 | # types of travel |
||
103 | const MOVE = 0; # déplacement |
||
104 | const LOOT = 1; # pillage |
||
105 | const COLO = 2; # colo ou conquete |
||
106 | const BACK = 3; # retour après une action |
||
107 | |||
108 | const MAXTRAVELTIME = 57600; |
||
109 | const DISTANCEMAX = 30; |
||
110 | |||
111 | # Const de lineCoord |
||
112 | public static $LINECOORD = array(1, 1, 1, 2, 2, 1, 2, 3, 3, 1, 2, 3, 4, 4, 2, 3, 4, 5, 5, 3, 4, 5, 6, 6, 4, 5, 6, 7, 7, 5, 6, 7); |
||
113 | |||
114 | /** |
||
115 | * @param int $id |
||
116 | * @return $this |
||
117 | */ |
||
118 | public function setId($id) |
||
124 | |||
125 | /** |
||
126 | * @return int |
||
127 | */ |
||
128 | public function getId() |
||
132 | |||
133 | /** |
||
134 | * @param string $name |
||
135 | * @return $this |
||
136 | */ |
||
137 | public function setName($name) |
||
143 | |||
144 | /** |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getName() |
||
151 | |||
152 | /** |
||
153 | * @param string $avatar |
||
154 | * @return $this |
||
155 | */ |
||
156 | public function setAvatar($avatar) |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getAvatar() |
||
170 | |||
171 | /** |
||
172 | * @param int $rPlayer |
||
173 | * @return $this |
||
174 | */ |
||
175 | public function setRPlayer($rPlayer) |
||
181 | |||
182 | /** |
||
183 | * @return int |
||
184 | */ |
||
185 | public function getRPlayer() |
||
189 | |||
190 | /** |
||
191 | * @param string $playerName |
||
192 | * @return $this |
||
193 | */ |
||
194 | public function setPlayerName($playerName) |
||
200 | |||
201 | /** |
||
202 | * @return string |
||
203 | */ |
||
204 | public function getPlayerName() |
||
208 | |||
209 | /** |
||
210 | * @param int $playerColor |
||
211 | * @return $this |
||
212 | */ |
||
213 | public function setPlayerColor($playerColor) |
||
219 | |||
220 | /** |
||
221 | * @return int |
||
222 | */ |
||
223 | public function getPlayerColor() |
||
227 | |||
228 | /** |
||
229 | * @param int $rBase |
||
230 | * @return $this |
||
231 | */ |
||
232 | public function setRBase($rBase) |
||
238 | |||
239 | /** |
||
240 | * @return int |
||
241 | */ |
||
242 | public function getRBase() |
||
246 | |||
247 | /** |
||
248 | * @param string $comment |
||
249 | * @return $this |
||
250 | */ |
||
251 | public function setComment($comment) |
||
257 | |||
258 | /** |
||
259 | * @return string |
||
260 | */ |
||
261 | public function getComment() |
||
265 | |||
266 | /** |
||
267 | * @param int $sexe |
||
268 | * @return $this |
||
269 | */ |
||
270 | public function setSexe($sexe) |
||
276 | |||
277 | /** |
||
278 | * @return int |
||
279 | */ |
||
280 | public function getSexe() |
||
284 | |||
285 | /** |
||
286 | * @param int $age |
||
287 | * @return $this |
||
288 | */ |
||
289 | public function setAge($age) |
||
295 | |||
296 | /** |
||
297 | * @return int |
||
298 | */ |
||
299 | public function getAge() |
||
303 | |||
304 | /** |
||
305 | * @param int $level |
||
306 | * @return $this |
||
307 | */ |
||
308 | public function setLevel($level) |
||
314 | |||
315 | /** |
||
316 | * @return int |
||
317 | */ |
||
318 | public function getLevel() |
||
322 | |||
323 | /** |
||
324 | * @param int $experience |
||
325 | * @return $this |
||
326 | */ |
||
327 | public function setExperience($experience) |
||
333 | |||
334 | /** |
||
335 | * @return int |
||
336 | */ |
||
337 | public function getExperience() |
||
341 | |||
342 | /** |
||
343 | * @param int $earnedExperience |
||
344 | * @return $this |
||
345 | */ |
||
346 | public function setEarnedExperience($earnedExperience) |
||
352 | |||
353 | /** |
||
354 | * @return int |
||
355 | */ |
||
356 | public function getEarnedExperience() |
||
360 | |||
361 | /** |
||
362 | * @param string $updatedAt |
||
363 | * @return $this |
||
364 | */ |
||
365 | public function setUpdatedAt($updatedAt) |
||
366 | { |
||
367 | $this->uCommander = $updatedAt; |
||
368 | |||
369 | return $this; |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getUpdatedAt() |
||
376 | { |
||
377 | return $this->uCommander; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * @param int $palmares |
||
382 | * @return $this |
||
383 | */ |
||
384 | public function setPalmares($palmares) |
||
390 | |||
391 | /** |
||
392 | * @return int |
||
393 | */ |
||
394 | public function getPalmares() |
||
398 | |||
399 | /** |
||
400 | * @param int $travelType |
||
401 | */ |
||
402 | public function setTravelType($travelType) |
||
408 | |||
409 | /** |
||
410 | * @return int |
||
411 | */ |
||
412 | public function getTravelType() |
||
416 | |||
417 | /** |
||
418 | * @param int $travelLength |
||
419 | * @return Commander |
||
420 | */ |
||
421 | public function setTravelLength($travelLength) |
||
427 | |||
428 | /** |
||
429 | * @return int |
||
430 | */ |
||
431 | public function getTravelLength() |
||
435 | |||
436 | /** |
||
437 | * @param int $startPlaceId |
||
438 | * @return Commander |
||
439 | */ |
||
440 | public function setStartPlaceId($startPlaceId) |
||
446 | |||
447 | /** |
||
448 | * @return int |
||
449 | */ |
||
450 | public function getStartPlaceId() |
||
454 | |||
455 | /** |
||
456 | * @param int $rDestinationPlace |
||
457 | * @return $this |
||
458 | */ |
||
459 | public function setRPlaceDestination($rDestinationPlace) |
||
465 | |||
466 | /** |
||
467 | * @return int |
||
468 | */ |
||
469 | public function getRPlaceDestination() |
||
473 | |||
474 | /** |
||
475 | * @param int $resources |
||
476 | * @return $this |
||
477 | */ |
||
478 | public function setResources($resources) |
||
484 | |||
485 | /** |
||
486 | * @return int |
||
487 | */ |
||
488 | public function getResources() |
||
492 | |||
493 | /** |
||
494 | * @param int $statement |
||
495 | * @return $this |
||
496 | */ |
||
497 | public function setStatement($statement) |
||
503 | |||
504 | /** |
||
505 | * @return int |
||
506 | */ |
||
507 | public function getStatement() |
||
511 | |||
512 | /** |
||
513 | * @param string $dCreation |
||
514 | * @return $this |
||
515 | */ |
||
516 | public function setDCreation($dCreation) |
||
522 | |||
523 | /** |
||
524 | * @return string |
||
525 | */ |
||
526 | public function getDCreation() |
||
530 | |||
531 | /** |
||
532 | * @param string $dAffectation |
||
533 | * @return $this |
||
534 | */ |
||
535 | public function setDAffectation($dAffectation) |
||
541 | |||
542 | /** |
||
543 | * @return string |
||
544 | */ |
||
545 | public function getDAffectation() |
||
549 | |||
550 | /** |
||
551 | * @param string $startedAt |
||
552 | * @return \Asylamba\Modules\Ares\Model\Commander |
||
553 | */ |
||
554 | public function setStartedAt($startedAt) |
||
560 | |||
561 | /** |
||
562 | * @return string |
||
563 | */ |
||
564 | public function getStartedAt() |
||
568 | |||
569 | /** |
||
570 | * @param string $arrivalDate |
||
571 | * @return $this |
||
572 | */ |
||
573 | public function setArrivalDate($arrivalDate) |
||
579 | |||
580 | /** |
||
581 | * @return string |
||
582 | */ |
||
583 | public function getArrivalDate() |
||
587 | |||
588 | /** |
||
589 | * @param string $dDeath |
||
590 | * @return $this |
||
591 | */ |
||
592 | public function setDDeath($dDeath) |
||
598 | |||
599 | /** |
||
600 | * @return string |
||
601 | */ |
||
602 | public function getDDeath() |
||
606 | |||
607 | /** |
||
608 | * @param int $lengthTravel |
||
609 | * @return $this |
||
610 | */ |
||
611 | public function setLengthTravel($lengthTravel) |
||
617 | |||
618 | /** |
||
619 | * @return int |
||
620 | */ |
||
621 | public function getLengthTravel() |
||
625 | |||
626 | /** |
||
627 | * @param string $oBName |
||
628 | * @return $this |
||
629 | */ |
||
630 | public function setBaseName($oBName) |
||
636 | |||
637 | /** |
||
638 | * @return string |
||
639 | */ |
||
640 | public function getBaseName() |
||
644 | |||
645 | /** |
||
646 | * @param string $doName |
||
647 | * @return $this |
||
648 | */ |
||
649 | public function setDestinationPlaceName($doName) |
||
655 | |||
656 | /** |
||
657 | * @return string |
||
658 | */ |
||
659 | public function getDestinationPlaceName() |
||
663 | |||
664 | /** |
||
665 | * @param array $squadronsIds |
||
666 | * @return $this |
||
667 | */ |
||
668 | public function setSquadronsIds($squadronsIds) |
||
674 | |||
675 | /** |
||
676 | * @param int $squadronId |
||
677 | * @return $this |
||
678 | */ |
||
679 | public function addSquadronId($squadronId) |
||
685 | |||
686 | /** |
||
687 | * @return array |
||
688 | */ |
||
689 | public function getSquadronsIds() |
||
693 | |||
694 | /** |
||
695 | * @param array $armyInBegin |
||
696 | * @return $this |
||
697 | */ |
||
698 | public function setArmyInBegin($armyInBegin) |
||
704 | |||
705 | /** |
||
706 | * @param array $army |
||
707 | * @return $this |
||
708 | */ |
||
709 | public function addArmyInBegin($army) |
||
715 | |||
716 | /** |
||
717 | * @return array |
||
718 | */ |
||
719 | public function getArmyInBegin() |
||
723 | |||
724 | /** |
||
725 | * @param bool $isAttacker |
||
726 | * @return $this |
||
727 | */ |
||
728 | public function setIsAttacker($isAttacker) |
||
734 | |||
735 | /** |
||
736 | * @return bool |
||
737 | */ |
||
738 | public function getIsAttacker() |
||
742 | |||
743 | public function setArmy() |
||
758 | |||
759 | public function getArmy() |
||
764 | |||
765 | public function setPevInBegin() { |
||
774 | |||
775 | public function getPevInBegin() |
||
779 | |||
780 | public function getPev() { |
||
789 | |||
790 | public function setArmyAtEnd() |
||
799 | |||
800 | public function getArmyAtEnd() |
||
804 | |||
805 | public function getFormatLineCoord() |
||
814 | |||
815 | public function getSizeArmy() |
||
819 | |||
820 | public function getPevToLoot() |
||
835 | |||
836 | public function getSquadron($i) |
||
845 | |||
846 | # renvoie un tableau de nombre de vaisseaux |
||
847 | public function getNbrShipByType() |
||
857 | } |