Complex classes like Map 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 Map, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | class Map implements VariableAwareInterface |
||
29 | { |
||
30 | use VariableAwareTrait; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $htmlId = 'map_canvas'; |
||
36 | |||
37 | /** |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $autoZoom = false; |
||
41 | |||
42 | /** |
||
43 | * @var Coordinate |
||
44 | */ |
||
45 | private $center; |
||
46 | |||
47 | /** |
||
48 | * @var Bound |
||
49 | */ |
||
50 | private $bound; |
||
51 | |||
52 | /** |
||
53 | * @var ControlManager |
||
54 | */ |
||
55 | private $controlManager; |
||
56 | |||
57 | /** |
||
58 | * @var EventManager |
||
59 | */ |
||
60 | private $eventManager; |
||
61 | |||
62 | /** |
||
63 | * @var LayerManager |
||
64 | */ |
||
65 | private $layerManager; |
||
66 | |||
67 | /** |
||
68 | * @var OverlayManager |
||
69 | */ |
||
70 | private $overlayManager; |
||
71 | |||
72 | /** |
||
73 | * @var string[] |
||
74 | */ |
||
75 | private $libraries = []; |
||
76 | |||
77 | /** |
||
78 | * @var mixed[] |
||
79 | */ |
||
80 | private $mapOptions = []; |
||
81 | |||
82 | /** |
||
83 | * @var string[] |
||
84 | */ |
||
85 | private $stylesheetOptions = []; |
||
86 | |||
87 | public function __construct() |
||
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getHtmlId() |
||
105 | |||
106 | /** |
||
107 | * @param string $htmlId |
||
108 | */ |
||
109 | public function setHtmlId($htmlId) |
||
113 | |||
114 | /** |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function isAutoZoom() |
||
121 | |||
122 | /** |
||
123 | * @param bool $autoZoom |
||
124 | */ |
||
125 | public function setAutoZoom($autoZoom) |
||
129 | |||
130 | /** |
||
131 | * @return Coordinate |
||
132 | */ |
||
133 | public function getCenter() |
||
137 | |||
138 | /** |
||
139 | * @param Coordinate $center |
||
140 | */ |
||
141 | public function setCenter(Coordinate $center) |
||
145 | |||
146 | /** |
||
147 | * @return Bound |
||
148 | */ |
||
149 | public function getBound() |
||
153 | |||
154 | /** |
||
155 | * @param Bound $bound |
||
156 | */ |
||
157 | public function setBound(Bound $bound) |
||
161 | |||
162 | /** |
||
163 | * @return ControlManager |
||
164 | */ |
||
165 | public function getControlManager() |
||
169 | |||
170 | /** |
||
171 | * @param ControlManager $controlManager |
||
172 | */ |
||
173 | public function setControlManager(ControlManager $controlManager) |
||
181 | |||
182 | /** |
||
183 | * @return EventManager |
||
184 | */ |
||
185 | public function getEventManager() |
||
189 | |||
190 | /** |
||
191 | * @param EventManager $eventManager |
||
192 | */ |
||
193 | public function setEventManager(EventManager $eventManager) |
||
201 | |||
202 | /** |
||
203 | * @return LayerManager |
||
204 | */ |
||
205 | public function getLayerManager() |
||
209 | |||
210 | /** |
||
211 | * @param LayerManager $layerManager |
||
212 | */ |
||
213 | public function setLayerManager(LayerManager $layerManager) |
||
221 | |||
222 | /** |
||
223 | * @return OverlayManager |
||
224 | */ |
||
225 | public function getOverlayManager() |
||
229 | |||
230 | /** |
||
231 | * @param OverlayManager $overlayManager |
||
232 | */ |
||
233 | public function setOverlayManager(OverlayManager $overlayManager) |
||
241 | |||
242 | /** |
||
243 | * @return bool |
||
244 | */ |
||
245 | public function hasLibraries() |
||
249 | |||
250 | /** |
||
251 | * @return string[] |
||
252 | */ |
||
253 | public function getLibraries() |
||
257 | |||
258 | /** |
||
259 | * @param string[] $libraries |
||
260 | */ |
||
261 | public function setLibraries(array $libraries) |
||
266 | |||
267 | /** |
||
268 | * @param string[] $libraries |
||
269 | */ |
||
270 | public function addLibraries(array $libraries) |
||
276 | |||
277 | /** |
||
278 | * @param string $library |
||
279 | * |
||
280 | * @return bool |
||
281 | */ |
||
282 | public function hasLibrary($library) |
||
286 | |||
287 | /** |
||
288 | * @param string $library |
||
289 | */ |
||
290 | public function addLibrary($library) |
||
296 | |||
297 | /** |
||
298 | * @param string $library |
||
299 | */ |
||
300 | public function removeLibrary($library) |
||
304 | |||
305 | /** |
||
306 | * @return bool |
||
307 | */ |
||
308 | public function hasMapOptions() |
||
312 | |||
313 | /** |
||
314 | * @return mixed[] |
||
315 | */ |
||
316 | public function getMapOptions() |
||
320 | |||
321 | /** |
||
322 | * @param mixed[] $mapOptions |
||
323 | */ |
||
324 | public function setMapOptions(array $mapOptions) |
||
329 | |||
330 | /** |
||
331 | * @param mixed[] $mapOptions |
||
332 | */ |
||
333 | public function addMapOptions(array $mapOptions) |
||
339 | |||
340 | /** |
||
341 | * @param string $mapOption |
||
342 | * |
||
343 | * @return bool |
||
344 | */ |
||
345 | public function hasMapOption($mapOption) |
||
349 | |||
350 | /** |
||
351 | * @param string $mapOption |
||
352 | * |
||
353 | * @return mixed |
||
354 | */ |
||
355 | public function getMapOption($mapOption) |
||
359 | |||
360 | /** |
||
361 | * @param string $mapOption |
||
362 | * @param mixed $value |
||
363 | */ |
||
364 | public function setMapOption($mapOption, $value) |
||
368 | |||
369 | /** |
||
370 | * @param string $mapOption |
||
371 | */ |
||
372 | public function removeMapOption($mapOption) |
||
376 | |||
377 | /** |
||
378 | * @return bool |
||
379 | */ |
||
380 | public function hasStylesheetOptions() |
||
384 | |||
385 | /** |
||
386 | * @return string[] |
||
387 | */ |
||
388 | public function getStylesheetOptions() |
||
392 | |||
393 | /** |
||
394 | * @param string[] $stylesheetOptions |
||
395 | */ |
||
396 | public function setStylesheetOptions(array $stylesheetOptions) |
||
401 | |||
402 | /** |
||
403 | * @param string[] $stylesheetOptions |
||
404 | */ |
||
405 | public function addStylesheetOptions(array $stylesheetOptions) |
||
411 | |||
412 | /** |
||
413 | * @param string $stylesheetOption |
||
414 | * |
||
415 | * @return bool |
||
416 | */ |
||
417 | public function hasStylesheetOption($stylesheetOption) |
||
421 | |||
422 | /** |
||
423 | * @param string $stylesheetOption |
||
424 | * |
||
425 | * @return string|null |
||
426 | */ |
||
427 | public function getStylesheetOption($stylesheetOption) |
||
431 | |||
432 | /** |
||
433 | * @param string $stylesheetOption |
||
434 | * @param string $value |
||
435 | */ |
||
436 | public function setStylesheetOption($stylesheetOption, $value) |
||
440 | |||
441 | /** |
||
442 | * @param string $stylesheetOption |
||
443 | */ |
||
444 | public function removeStylesheetOption($stylesheetOption) |
||
448 | } |
||
449 |