Complex classes like Api 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 Api, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class Api extends Base |
||
9 | { |
||
10 | public $motd; |
||
11 | |||
12 | public $crestEndpoint; |
||
13 | |||
14 | public $corporationRoles; |
||
15 | |||
16 | public $itemGroups; |
||
17 | |||
18 | public $channels; |
||
19 | |||
20 | public $corporations; |
||
21 | |||
22 | public $alliances; |
||
23 | |||
24 | public $itemTypes; |
||
25 | |||
26 | public $decode; |
||
27 | |||
28 | public $battleTheatres; |
||
29 | |||
30 | public $marketPrices; |
||
31 | |||
32 | public $itemCategories; |
||
33 | |||
34 | public $regions; |
||
35 | |||
36 | public $bloodlines; |
||
37 | |||
38 | public $marketGroups; |
||
39 | |||
40 | public $sovereignty; |
||
41 | |||
42 | public $tournaments; |
||
43 | |||
44 | public $map; |
||
45 | |||
46 | public $virtualGoodStore; |
||
47 | |||
48 | public $serverVersion; |
||
49 | |||
50 | public $wars; |
||
51 | |||
52 | public $incursions; |
||
53 | |||
54 | public $races; |
||
55 | |||
56 | public $authEndpoint; |
||
57 | |||
58 | public $serviceStatus; |
||
59 | |||
60 | public $userCounts; |
||
61 | |||
62 | public $industry; |
||
63 | |||
64 | public $clients; |
||
65 | |||
66 | public $time; |
||
67 | |||
68 | public $marketTypes; |
||
69 | |||
70 | public $serverName; |
||
71 | |||
72 | // by Warringer\Types\Dict |
||
73 | public function setMotd($motd) |
||
90 | |||
91 | // by Warringer\Types\Reference |
||
92 | public function setCrestEndpoint($crestEndpoint) |
||
96 | |||
97 | // by Warringer\Types\Reference |
||
98 | public function setCorporationRoles($corporationRoles) |
||
102 | |||
103 | // by Warringer\Types\Reference |
||
104 | public function setItemGroups($itemGroups) |
||
108 | |||
109 | // by Warringer\Types\Reference |
||
110 | public function setChannels($channels) |
||
114 | |||
115 | // by Warringer\Types\Reference |
||
116 | public function setCorporations($corporations) |
||
120 | |||
121 | // by Warringer\Types\Reference |
||
122 | public function setAlliances($alliances) |
||
126 | |||
127 | // by Warringer\Types\Reference |
||
128 | public function setItemTypes($itemTypes) |
||
132 | |||
133 | // by Warringer\Types\Reference |
||
134 | public function setDecode($decode) |
||
138 | |||
139 | // by Warringer\Types\Reference |
||
140 | public function setBattleTheatres($battleTheatres) |
||
144 | |||
145 | // by Warringer\Types\Reference |
||
146 | public function setMarketPrices($marketPrices) |
||
150 | |||
151 | // by Warringer\Types\Reference |
||
152 | public function setItemCategories($itemCategories) |
||
156 | |||
157 | // by Warringer\Types\Reference |
||
158 | public function setRegions($regions) |
||
162 | |||
163 | // by Warringer\Types\Reference |
||
164 | public function setBloodlines($bloodlines) |
||
168 | |||
169 | // by Warringer\Types\Reference |
||
170 | public function setMarketGroups($marketGroups) |
||
174 | |||
175 | // by Warringer\Types\Dict |
||
176 | public function setSovereignty($sovereignty) |
||
191 | |||
192 | // by Warringer\Types\Reference |
||
193 | public function setTournaments($tournaments) |
||
197 | |||
198 | // by Warringer\Types\Reference |
||
199 | public function setMap($map) |
||
203 | |||
204 | // by Warringer\Types\Reference |
||
205 | public function setVirtualGoodStore($virtualGoodStore) |
||
209 | |||
210 | // by Warringer\Types\String |
||
211 | public function setServerVersion($serverVersion) |
||
215 | |||
216 | // by Warringer\Types\Reference |
||
217 | public function setWars($wars) |
||
221 | |||
222 | // by Warringer\Types\Reference |
||
223 | public function setIncursions($incursions) |
||
227 | |||
228 | // by Warringer\Types\Reference |
||
229 | public function setRaces($races) |
||
233 | |||
234 | // by Warringer\Types\Reference |
||
235 | public function setAuthEndpoint($authEndpoint) |
||
239 | |||
240 | // by Warringer\Types\Dict |
||
241 | public function setServiceStatus($serviceStatus) |
||
258 | |||
259 | // by Warringer\Types\Dict |
||
260 | public function setUserCounts($userCounts) |
||
275 | |||
276 | // by Warringer\Types\Dict |
||
277 | public function setIndustry($industry) |
||
292 | |||
293 | // by Warringer\Types\Dict |
||
294 | public function setClients($clients) |
||
309 | |||
310 | // by Warringer\Types\Reference |
||
311 | public function setTime($time) |
||
315 | |||
316 | // by Warringer\Types\Reference |
||
317 | public function setMarketTypes($marketTypes) |
||
321 | |||
322 | // by Warringer\Types\String |
||
323 | public function setServerName($serverName) |
||
327 | |||
328 | } |
||
329 |