Complex classes like FactionRanking 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 FactionRanking, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class FactionRanking { |
||
18 | |||
19 | # attributes |
||
20 | public $id; |
||
21 | public $rRanking; |
||
22 | public $rFaction; |
||
23 | |||
24 | public $points; # accumulated points |
||
25 | public $pointsPosition; |
||
26 | public $pointsVariation; |
||
27 | public $newPoints; |
||
28 | |||
29 | public $general; # sum of general ranking of the players |
||
30 | public $generalPosition; |
||
31 | public $generalVariation; |
||
32 | |||
33 | public $wealth; # credits |
||
34 | public $wealthPosition; |
||
35 | public $wealthVariation; |
||
36 | |||
37 | public $territorial; # sectors owned |
||
38 | public $territorialPosition; |
||
39 | public $territorialVariation; |
||
40 | |||
41 | /** |
||
42 | * @param int $id |
||
43 | * @return FactionRanking |
||
44 | */ |
||
45 | public function setId($id) |
||
51 | |||
52 | /** |
||
53 | * @return int |
||
54 | */ |
||
55 | public function getId() |
||
59 | |||
60 | /** |
||
61 | * @param int $rankingId |
||
62 | * @return FactionRanking |
||
63 | */ |
||
64 | public function setRankingId($rankingId) |
||
70 | |||
71 | /** |
||
72 | * @return int |
||
73 | */ |
||
74 | public function getRankingId() |
||
78 | |||
79 | /** |
||
80 | * @param int $factionId |
||
81 | * @return FactionRanking |
||
82 | */ |
||
83 | public function setFactionId($factionId) |
||
89 | |||
90 | /** |
||
91 | * @return int |
||
92 | */ |
||
93 | public function getFactionId() |
||
97 | |||
98 | /** |
||
99 | * @param int $points |
||
100 | * @return FactionRanking |
||
101 | */ |
||
102 | public function setPoints($points) |
||
108 | |||
109 | /** |
||
110 | * @return int |
||
111 | */ |
||
112 | public function getPoints() |
||
116 | |||
117 | /** |
||
118 | * @param int $pointsPosition |
||
119 | * @return FactionRanking |
||
120 | */ |
||
121 | public function setPointsPosition($pointsPosition) |
||
127 | |||
128 | /** |
||
129 | * @return int |
||
130 | */ |
||
131 | public function getPointsPosition() |
||
135 | |||
136 | /** |
||
137 | * @param int $pointsVariation |
||
138 | * @return FactionRanking |
||
139 | */ |
||
140 | public function setPointsVariation($pointsVariation) |
||
146 | |||
147 | /** |
||
148 | * @return int |
||
149 | */ |
||
150 | public function getPointsVariation() |
||
154 | |||
155 | /** |
||
156 | * @param int $newPoints |
||
157 | * @return FactionRanking |
||
158 | */ |
||
159 | public function setNewPoints($newPoints) |
||
165 | |||
166 | /** |
||
167 | * @return int |
||
168 | */ |
||
169 | public function getNewPoints() |
||
173 | |||
174 | /** |
||
175 | * @param int $general |
||
176 | * @return FactionRanking |
||
177 | */ |
||
178 | public function setGeneral($general) |
||
184 | |||
185 | /** |
||
186 | * @return int |
||
187 | */ |
||
188 | public function getGeneral() |
||
192 | |||
193 | /** |
||
194 | * @param int $generalPosition |
||
195 | * @return FactionRanking |
||
196 | */ |
||
197 | public function setGeneralPosition($generalPosition) |
||
203 | |||
204 | /** |
||
205 | * @return int |
||
206 | */ |
||
207 | public function getGeneralPosition() |
||
211 | |||
212 | /** |
||
213 | * @param int $generalVariation |
||
214 | * @return FactionRanking |
||
215 | */ |
||
216 | public function setGeneralVariation($generalVariation) |
||
222 | |||
223 | /** |
||
224 | * @return int |
||
225 | */ |
||
226 | public function getGeneralVariation() |
||
230 | |||
231 | /** |
||
232 | * @param int $wealth |
||
233 | * @return FactionRanking |
||
234 | */ |
||
235 | public function setWealth($wealth) |
||
241 | |||
242 | /** |
||
243 | * @return int |
||
244 | */ |
||
245 | public function getWealth() |
||
249 | |||
250 | /** |
||
251 | * @param int $wealthPosition |
||
252 | * @return FactionRanking |
||
253 | */ |
||
254 | public function setWealthPosition($wealthPosition) |
||
260 | |||
261 | /** |
||
262 | * @return int |
||
263 | */ |
||
264 | public function getWealthPosition() |
||
268 | |||
269 | /** |
||
270 | * @param int $wealthVariation |
||
271 | * @return FactionRanking |
||
272 | */ |
||
273 | public function setWealthVariation($wealthVariation) |
||
279 | |||
280 | /** |
||
281 | * @return int |
||
282 | */ |
||
283 | public function getWealthVariation() |
||
287 | |||
288 | /** |
||
289 | * @param int $territorial |
||
290 | * @return FactionRanking |
||
291 | */ |
||
292 | public function setTerritorial($territorial) |
||
298 | |||
299 | /** |
||
300 | * @return int |
||
301 | */ |
||
302 | public function getTerritorial() |
||
306 | |||
307 | /** |
||
308 | * @param int $territorialPosition |
||
309 | * @return FactionRanking |
||
310 | */ |
||
311 | public function setTerritorialPosition($territorialPosition) |
||
317 | |||
318 | /** |
||
319 | * @return int |
||
320 | */ |
||
321 | public function getTerritorialPosition() |
||
325 | |||
326 | /** |
||
327 | * @param int $territorialVariation |
||
328 | * @return FactionRanking |
||
329 | */ |
||
330 | public function setTerritorialVariation($territorialVariation) |
||
336 | |||
337 | /** |
||
338 | * @return int |
||
339 | */ |
||
340 | public function getTerritorialVariation() |
||
344 | |||
345 | public function commonRender($playerInfo, $type = 'general') { |
||
397 | } |
||
398 |
As per the PSR-2 coding standard, the
break
(or other terminating) statement must be on a line of its own.To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.