Complex classes like Army 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 Army, and based on these observations, apply Extract Interface, too.
1 | <?php namespace Xaoc303\BattleCalc; |
||
7 | class Army |
||
8 | { |
||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | private $units; |
||
13 | |||
14 | /** |
||
15 | * __construct |
||
16 | * |
||
17 | * @param array $input_units |
||
18 | */ |
||
19 | public function __construct($input_units) |
||
24 | |||
25 | /** |
||
26 | * setUnits |
||
27 | * |
||
28 | * @param array $units |
||
29 | */ |
||
30 | public function setUnits($units) |
||
34 | |||
35 | /** |
||
36 | * getUnits |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | public function getUnits() |
||
44 | |||
45 | /** |
||
46 | * manCount |
||
47 | * |
||
48 | * @param integer $Inic |
||
49 | * @return int |
||
50 | */ |
||
51 | public function manCount(&$Inic) |
||
66 | |||
67 | /** |
||
68 | * shadow |
||
69 | * |
||
70 | * @param Army $ArmyDet |
||
71 | * @param integer $Round |
||
72 | */ |
||
73 | public function shadow(Army &$ArmyDet, $Round) |
||
94 | |||
95 | /** |
||
96 | * setShadow |
||
97 | * |
||
98 | * @param array $unitsSh |
||
99 | * @param int $i |
||
100 | * @param int $units_count |
||
101 | * @param int $Round |
||
102 | */ |
||
103 | private function setShadow(&$unitsSh, &$i, &$units_count, $Round) |
||
128 | |||
129 | /** |
||
130 | * setShadowSquadAll |
||
131 | * |
||
132 | * @param array $unitsSh |
||
133 | * @param int $i |
||
134 | */ |
||
135 | private function setShadowSquadAll(&$unitsSh, &$i) |
||
139 | |||
140 | /** |
||
141 | * setShadowSquad114 |
||
142 | * |
||
143 | * @param array $unitsSh |
||
144 | * @param int $i |
||
145 | * @param int $units_count |
||
146 | */ |
||
147 | private function setShadowSquad114(&$unitsSh, &$i, &$units_count) |
||
170 | |||
171 | /** |
||
172 | * setShadowSquadRound |
||
173 | * |
||
174 | * @param array $unitsSh |
||
175 | * @param int $i |
||
176 | * @param int $Round |
||
177 | */ |
||
178 | private function setShadowSquadRound(&$unitsSh, &$i, &$Round) |
||
186 | |||
187 | /** |
||
188 | * setShadowSquadAllHold |
||
189 | * |
||
190 | * @param array $unitsSh |
||
191 | * @param int $i |
||
192 | * @param null|int $Round |
||
193 | */ |
||
194 | private function setShadowSquadAllHold(&$unitsSh, &$i, $Round = null) |
||
200 | |||
201 | /** |
||
202 | * getDetectorsCount |
||
203 | * |
||
204 | * @param array $unitsDet |
||
205 | * @return int |
||
206 | */ |
||
207 | private function getDetectorsCount(&$unitsDet) |
||
218 | |||
219 | /** |
||
220 | * unsetShadow |
||
221 | * |
||
222 | * @param array $unitsSh |
||
223 | * @param int $ManCount |
||
224 | */ |
||
225 | private function unsetShadow(&$unitsSh, $ManCount) |
||
245 | |||
246 | /** |
||
247 | * clear |
||
248 | */ |
||
249 | public function clear() |
||
270 | |||
271 | |||
272 | |||
273 | /** |
||
274 | * manCountVisible |
||
275 | * |
||
276 | * @param integer $unit_type |
||
277 | * @return int |
||
278 | */ |
||
279 | public function manCountVisible($unit_type) |
||
292 | |||
293 | /** |
||
294 | * attackNull |
||
295 | * |
||
296 | * @param integer $ManCountA |
||
297 | */ |
||
298 | public function attackNull($ManCountA) |
||
330 | |||
331 | /** |
||
332 | * count |
||
333 | * |
||
334 | * @return int |
||
335 | */ |
||
336 | public function count() |
||
359 | } |
||
360 |