Complex classes like Player 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 Player, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Player |
||
22 | { |
||
23 | /** @var string */ |
||
24 | protected $login; |
||
25 | |||
26 | /** @var bool */ |
||
27 | protected $isConnected = true; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $nickName; |
||
31 | |||
32 | /** @var int */ |
||
33 | protected $playerId; |
||
34 | |||
35 | /** @var int */ |
||
36 | protected $teamId; |
||
37 | |||
38 | /** @var bool */ |
||
39 | protected $isInOfficialMode; |
||
40 | |||
41 | /** @var int */ |
||
42 | protected $ladderRanking; |
||
43 | |||
44 | /** @var int */ |
||
45 | protected $spectatorStatus; |
||
46 | |||
47 | /** @var int */ |
||
48 | protected $flags; |
||
49 | |||
50 | /** @var int */ |
||
51 | protected $forceSpectator; |
||
52 | |||
53 | /** @var bool */ |
||
54 | protected $isReferee; |
||
55 | |||
56 | /** @var bool */ |
||
57 | protected $isPodiumReady; |
||
58 | |||
59 | /** @var bool */ |
||
60 | protected $isUsingStereoscopy; |
||
61 | |||
62 | /** @var bool */ |
||
63 | protected $isManagedByAnOtherServer; |
||
64 | |||
65 | /** @var bool */ |
||
66 | protected $isServer; |
||
67 | |||
68 | /** @var bool */ |
||
69 | protected $hasPlayerSlot; |
||
70 | |||
71 | /** @var bool */ |
||
72 | protected $isBroadcasting; |
||
73 | |||
74 | /** @var bool */ |
||
75 | protected $hasJoinedGame = false; |
||
76 | |||
77 | /** @var bool */ |
||
78 | protected $spectator; |
||
79 | |||
80 | /** @var bool */ |
||
81 | protected $temporarySpectator; |
||
82 | |||
83 | /** @var bool */ |
||
84 | protected $pureSpectator; |
||
85 | |||
86 | /** @var bool */ |
||
87 | protected $autoTarget; |
||
88 | |||
89 | /** @var int */ |
||
90 | protected $currentTargetId; |
||
91 | |||
92 | /** @var string */ |
||
93 | protected $path; |
||
94 | |||
95 | /** @var string */ |
||
96 | protected $language; |
||
97 | |||
98 | /** @var string */ |
||
99 | protected $clientVersion; |
||
100 | |||
101 | /** @var string */ |
||
102 | protected $clientTitleVersion; |
||
103 | |||
104 | /** @var string */ |
||
105 | protected $iPAddress; |
||
106 | |||
107 | /** @var int */ |
||
108 | protected $downloadRate; |
||
109 | |||
110 | /** @var int */ |
||
111 | protected $uploadRate; |
||
112 | |||
113 | /** @var FileDesc */ |
||
114 | protected $avatar; |
||
115 | |||
116 | /** @var Skin[] */ |
||
117 | protected $skins; |
||
118 | |||
119 | /** @var LadderStats */ |
||
120 | protected $ladderStats; |
||
121 | |||
122 | /** @var int */ |
||
123 | protected $hoursSinceZoneInscription; |
||
124 | |||
125 | /** @var string */ |
||
126 | protected $broadcasterLogin; |
||
127 | |||
128 | /** @var string[] */ |
||
129 | protected $allies = array(); |
||
130 | |||
131 | /** @var string */ |
||
132 | protected $clubLink; |
||
133 | /** @var int */ |
||
134 | protected $rank; |
||
135 | |||
136 | /** @var int */ |
||
137 | protected $bestTime; |
||
138 | |||
139 | /** @var int[] */ |
||
140 | protected $bestCheckpoints; |
||
141 | |||
142 | /** @var int */ |
||
143 | protected $score; |
||
144 | |||
145 | /** @var int */ |
||
146 | protected $nbrLapsFinished; |
||
147 | |||
148 | /** @var float */ |
||
149 | protected $ladderScore; |
||
150 | |||
151 | /** |
||
152 | * @return boolean |
||
153 | */ |
||
154 | 1 | public function isIsConnected() |
|
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | 13 | public function getNickName() |
|
166 | |||
167 | /** |
||
168 | * @return int |
||
169 | */ |
||
170 | 2 | public function getPlayerId() |
|
174 | |||
175 | /** |
||
176 | * @return int |
||
177 | */ |
||
178 | 1 | public function getTeamId() |
|
182 | |||
183 | /** |
||
184 | * @return boolean |
||
185 | */ |
||
186 | public function isIsSpectator() |
||
190 | |||
191 | /** |
||
192 | * @return boolean |
||
193 | */ |
||
194 | 1 | public function isIsInOfficialMode() |
|
198 | |||
199 | /** |
||
200 | * @return int |
||
201 | */ |
||
202 | 1 | public function getLadderRanking() |
|
206 | |||
207 | /** |
||
208 | * @return int |
||
209 | */ |
||
210 | 2 | public function getSpectatorStatus() |
|
214 | |||
215 | /** |
||
216 | * @return int |
||
217 | */ |
||
218 | 1 | public function getFlags() |
|
222 | |||
223 | /** |
||
224 | * @return int |
||
225 | */ |
||
226 | 1 | public function getForceSpectator() |
|
230 | |||
231 | /** |
||
232 | * @return boolean |
||
233 | */ |
||
234 | 1 | public function isIsReferee() |
|
238 | |||
239 | /** |
||
240 | * @return boolean |
||
241 | */ |
||
242 | 1 | public function isIsPodiumReady() |
|
246 | |||
247 | /** |
||
248 | * @return boolean |
||
249 | */ |
||
250 | 1 | public function isIsUsingStereoscopy() |
|
254 | |||
255 | /** |
||
256 | * @return boolean |
||
257 | */ |
||
258 | 1 | public function isIsManagedByAnOtherServer() |
|
262 | |||
263 | /** |
||
264 | * @return boolean |
||
265 | */ |
||
266 | 2 | public function isIsServer() |
|
270 | |||
271 | /** |
||
272 | * @return boolean |
||
273 | */ |
||
274 | 1 | public function isHasPlayerSlot() |
|
278 | |||
279 | /** |
||
280 | * @return boolean |
||
281 | */ |
||
282 | 1 | public function isIsBroadcasting() |
|
286 | |||
287 | /** |
||
288 | * @return boolean |
||
289 | */ |
||
290 | 1 | public function isHasJoinedGame() |
|
294 | |||
295 | /** |
||
296 | * @return boolean |
||
297 | */ |
||
298 | 9 | public function isSpectator() |
|
299 | { |
||
300 | 9 | return $this->spectatorStatus != 0; |
|
301 | } |
||
302 | |||
303 | /** |
||
304 | * @return boolean |
||
305 | */ |
||
306 | 1 | public function isTemporarySpectator() |
|
310 | |||
311 | /** |
||
312 | * @return boolean |
||
313 | */ |
||
314 | 1 | public function isPureSpectator() |
|
318 | |||
319 | /** |
||
320 | * @return boolean |
||
321 | */ |
||
322 | 1 | public function isAutoTarget() |
|
326 | |||
327 | /** |
||
328 | * @return int |
||
329 | */ |
||
330 | 1 | public function getCurrentTargetId() |
|
334 | |||
335 | /** |
||
336 | * @return string |
||
337 | */ |
||
338 | 7 | public function getPath() |
|
342 | |||
343 | /** |
||
344 | * @return string |
||
345 | */ |
||
346 | 3 | public function getLanguage() |
|
350 | |||
351 | /** |
||
352 | * @return string |
||
353 | */ |
||
354 | 2 | public function getClientVersion() |
|
358 | |||
359 | /** |
||
360 | * @return string |
||
361 | */ |
||
362 | 1 | public function getClientTitleVersion() |
|
366 | |||
367 | /** |
||
368 | * @return string |
||
369 | */ |
||
370 | 1 | public function getIPAddress() |
|
374 | |||
375 | /** |
||
376 | * @return int |
||
377 | */ |
||
378 | 1 | public function getDownloadRate() |
|
382 | |||
383 | /** |
||
384 | * @return int |
||
385 | */ |
||
386 | 1 | public function getUploadRate() |
|
390 | |||
391 | /** |
||
392 | * @return FileDesc |
||
393 | */ |
||
394 | 1 | public function getAvatar() |
|
398 | |||
399 | /** |
||
400 | * @return Skin[] |
||
401 | */ |
||
402 | 1 | public function getSkins() |
|
406 | |||
407 | /** |
||
408 | * @return LadderStats |
||
409 | */ |
||
410 | 1 | public function getLadderStats() |
|
414 | |||
415 | /** |
||
416 | * @return int |
||
417 | */ |
||
418 | 1 | public function getHoursSinceZoneInscription() |
|
422 | |||
423 | /** |
||
424 | * @return string |
||
425 | */ |
||
426 | 1 | public function getBroadcasterLogin() |
|
430 | |||
431 | /** |
||
432 | * @return string[] |
||
433 | */ |
||
434 | 1 | public function getAllies() |
|
438 | |||
439 | /** |
||
440 | * @return string |
||
441 | */ |
||
442 | 1 | public function getClubLink() |
|
446 | |||
447 | /** |
||
448 | * @return int |
||
449 | */ |
||
450 | 1 | public function getRank() |
|
454 | |||
455 | /** |
||
456 | * @return int |
||
457 | */ |
||
458 | 1 | public function getBestTime() |
|
462 | |||
463 | /** |
||
464 | * @return int[] |
||
465 | */ |
||
466 | 1 | public function getBestCheckpoints() |
|
470 | |||
471 | /** |
||
472 | * @return int |
||
473 | */ |
||
474 | 1 | public function getScore() |
|
478 | |||
479 | /** |
||
480 | * @return int |
||
481 | */ |
||
482 | 1 | public function getNbrLapsFinished() |
|
486 | |||
487 | /** |
||
488 | * @return float |
||
489 | */ |
||
490 | 1 | public function getLadderScore() |
|
494 | |||
495 | /** |
||
496 | * @return string |
||
497 | */ |
||
498 | 22 | public function getLogin() |
|
502 | |||
503 | /** |
||
504 | * @param \Maniaplanet\DedicatedServer\Structures\Player|array $data |
||
505 | * |
||
506 | * @return $this |
||
507 | */ |
||
508 | 63 | public function merge($data) |
|
522 | |||
523 | /** |
||
524 | * |
||
525 | * @return string |
||
526 | */ |
||
527 | public function __toString() |
||
531 | } |
||
532 |