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 |
||
30 | class Map implements VariableAwareInterface, StaticOptionsAwareInterface |
||
31 | { |
||
32 | use StaticOptionsAwareTrait; |
||
33 | use VariableAwareTrait; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $htmlId = 'map_canvas'; |
||
39 | |||
40 | /** |
||
41 | * @var bool |
||
42 | */ |
||
43 | private $autoZoom = false; |
||
44 | |||
45 | /** |
||
46 | * @var Coordinate |
||
47 | */ |
||
48 | private $center; |
||
49 | |||
50 | /** |
||
51 | * @var Bound |
||
52 | */ |
||
53 | private $bound; |
||
54 | |||
55 | /** |
||
56 | * @var ControlManager |
||
57 | */ |
||
58 | private $controlManager; |
||
59 | |||
60 | /** |
||
61 | * @var EventManager |
||
62 | */ |
||
63 | private $eventManager; |
||
64 | |||
65 | /** |
||
66 | * @var LayerManager |
||
67 | */ |
||
68 | private $layerManager; |
||
69 | |||
70 | /** |
||
71 | * @var OverlayManager |
||
72 | */ |
||
73 | private $overlayManager; |
||
74 | |||
75 | /** |
||
76 | * @var string[] |
||
77 | */ |
||
78 | private $libraries = []; |
||
79 | |||
80 | /** |
||
81 | * @var mixed[] |
||
82 | */ |
||
83 | private $mapOptions = []; |
||
84 | |||
85 | /** |
||
86 | * @var string[] |
||
87 | */ |
||
88 | private $stylesheetOptions = []; |
||
89 | |||
90 | /** |
||
91 | * @var string[] |
||
92 | */ |
||
93 | private $htmlAttributes = []; |
||
94 | |||
95 | 696 | public function __construct() |
|
104 | |||
105 | /** |
||
106 | * @return string |
||
107 | */ |
||
108 | 256 | public function getHtmlId() |
|
112 | |||
113 | /** |
||
114 | * @param string $htmlId |
||
115 | */ |
||
116 | 4 | public function setHtmlId($htmlId) |
|
120 | |||
121 | /** |
||
122 | * @return bool |
||
123 | */ |
||
124 | 468 | public function isAutoZoom() |
|
128 | |||
129 | /** |
||
130 | * @param bool $autoZoom |
||
131 | */ |
||
132 | 96 | public function setAutoZoom($autoZoom) |
|
136 | |||
137 | /** |
||
138 | * @return Coordinate |
||
139 | */ |
||
140 | 276 | public function getCenter() |
|
144 | |||
145 | /** |
||
146 | * @param Coordinate $center |
||
147 | */ |
||
148 | 696 | public function setCenter(Coordinate $center) |
|
152 | |||
153 | /** |
||
154 | * @return Bound |
||
155 | */ |
||
156 | 260 | public function getBound() |
|
160 | |||
161 | /** |
||
162 | * @param Bound $bound |
||
163 | */ |
||
164 | 696 | public function setBound(Bound $bound) |
|
168 | |||
169 | /** |
||
170 | * @return ControlManager |
||
171 | */ |
||
172 | 244 | public function getControlManager() |
|
176 | |||
177 | /** |
||
178 | * @param ControlManager $controlManager |
||
179 | */ |
||
180 | 696 | public function setControlManager(ControlManager $controlManager) |
|
184 | |||
185 | /** |
||
186 | * @return EventManager |
||
187 | */ |
||
188 | 240 | public function getEventManager() |
|
192 | |||
193 | /** |
||
194 | * @param EventManager $eventManager |
||
195 | */ |
||
196 | 696 | public function setEventManager(EventManager $eventManager) |
|
200 | |||
201 | /** |
||
202 | * @return LayerManager |
||
203 | */ |
||
204 | 696 | public function getLayerManager() |
|
208 | |||
209 | /** |
||
210 | * @param LayerManager $layerManager |
||
211 | */ |
||
212 | 696 | public function setLayerManager(LayerManager $layerManager) |
|
220 | |||
221 | /** |
||
222 | * @return OverlayManager |
||
223 | */ |
||
224 | 732 | public function getOverlayManager() |
|
228 | |||
229 | /** |
||
230 | * @param OverlayManager $overlayManager |
||
231 | */ |
||
232 | 696 | public function setOverlayManager(OverlayManager $overlayManager) |
|
240 | |||
241 | /** |
||
242 | * @return bool |
||
243 | */ |
||
244 | 20 | public function hasLibraries() |
|
248 | |||
249 | /** |
||
250 | * @return string[] |
||
251 | */ |
||
252 | 236 | public function getLibraries() |
|
256 | |||
257 | /** |
||
258 | * @param string[] $libraries |
||
259 | */ |
||
260 | 8 | public function setLibraries(array $libraries) |
|
265 | |||
266 | /** |
||
267 | * @param string[] $libraries |
||
268 | */ |
||
269 | 8 | public function addLibraries(array $libraries) |
|
275 | |||
276 | /** |
||
277 | * @param string $library |
||
278 | * |
||
279 | * @return bool |
||
280 | */ |
||
281 | 20 | public function hasLibrary($library) |
|
285 | |||
286 | /** |
||
287 | * @param string $library |
||
288 | */ |
||
289 | 20 | public function addLibrary($library) |
|
295 | |||
296 | /** |
||
297 | * @param string $library |
||
298 | */ |
||
299 | 4 | public function removeLibrary($library) |
|
304 | |||
305 | /** |
||
306 | * @return bool |
||
307 | */ |
||
308 | 20 | public function hasMapOptions() |
|
312 | |||
313 | /** |
||
314 | * @return mixed[] |
||
315 | */ |
||
316 | 252 | public function getMapOptions() |
|
320 | |||
321 | /** |
||
322 | * @param mixed[] $mapOptions |
||
323 | */ |
||
324 | 12 | public function setMapOptions(array $mapOptions) |
|
329 | |||
330 | /** |
||
331 | * @param mixed[] $mapOptions |
||
332 | */ |
||
333 | 12 | public function addMapOptions(array $mapOptions) |
|
339 | |||
340 | /** |
||
341 | * @param string $mapOption |
||
342 | * |
||
343 | * @return bool |
||
344 | */ |
||
345 | 344 | public function hasMapOption($mapOption) |
|
349 | |||
350 | /** |
||
351 | * @param string $mapOption |
||
352 | * |
||
353 | * @return mixed |
||
354 | */ |
||
355 | 252 | public function getMapOption($mapOption) |
|
359 | |||
360 | /** |
||
361 | * @param string $mapOption |
||
362 | * @param mixed $value |
||
363 | */ |
||
364 | 48 | public function setMapOption($mapOption, $value) |
|
368 | |||
369 | /** |
||
370 | * @param string $mapOption |
||
371 | */ |
||
372 | 4 | public function removeMapOption($mapOption) |
|
376 | |||
377 | /** |
||
378 | * @return bool |
||
379 | */ |
||
380 | 236 | public function hasStylesheetOptions() |
|
384 | |||
385 | /** |
||
386 | * @return string[] |
||
387 | */ |
||
388 | 20 | public function getStylesheetOptions() |
|
392 | |||
393 | /** |
||
394 | * @param string[] $stylesheetOptions |
||
395 | */ |
||
396 | 8 | public function setStylesheetOptions(array $stylesheetOptions) |
|
401 | |||
402 | /** |
||
403 | * @param string[] $stylesheetOptions |
||
404 | */ |
||
405 | 8 | public function addStylesheetOptions(array $stylesheetOptions) |
|
411 | |||
412 | /** |
||
413 | * @param string $stylesheetOption |
||
414 | * |
||
415 | * @return bool |
||
416 | */ |
||
417 | 244 | public function hasStylesheetOption($stylesheetOption) |
|
421 | |||
422 | /** |
||
423 | * @param string $stylesheetOption |
||
424 | * |
||
425 | * @return string|null |
||
426 | */ |
||
427 | 16 | public function getStylesheetOption($stylesheetOption) |
|
431 | |||
432 | /** |
||
433 | * @param string $stylesheetOption |
||
434 | * @param string $value |
||
435 | */ |
||
436 | 20 | public function setStylesheetOption($stylesheetOption, $value) |
|
440 | |||
441 | /** |
||
442 | * @param string $stylesheetOption |
||
443 | */ |
||
444 | 4 | public function removeStylesheetOption($stylesheetOption) |
|
448 | |||
449 | /** |
||
450 | * @return bool |
||
451 | */ |
||
452 | 20 | public function hasHtmlAttributes() |
|
456 | |||
457 | /** |
||
458 | * @return string[] |
||
459 | */ |
||
460 | 252 | public function getHtmlAttributes() |
|
464 | |||
465 | /** |
||
466 | * @param string[] $htmlAttributes |
||
467 | */ |
||
468 | 12 | public function setHtmlAttributes(array $htmlAttributes) |
|
473 | |||
474 | /** |
||
475 | * @param string[] $htmlAttributes |
||
476 | */ |
||
477 | 12 | public function addHtmlAttributes(array $htmlAttributes) |
|
483 | |||
484 | /** |
||
485 | * @param string $htmlAttribute |
||
486 | * |
||
487 | * @return bool |
||
488 | */ |
||
489 | 12 | public function hasHtmlAttribute($htmlAttribute) |
|
493 | |||
494 | /** |
||
495 | * @param string $htmlAttribute |
||
496 | * |
||
497 | * @return string|null |
||
498 | */ |
||
499 | 12 | public function getHtmlAttribute($htmlAttribute) |
|
503 | |||
504 | /** |
||
505 | * @param string $htmlAttribute |
||
506 | * @param string $value |
||
507 | */ |
||
508 | 20 | public function setHtmlAttribute($htmlAttribute, $value) |
|
512 | |||
513 | /** |
||
514 | * @param string $htmlAttribute |
||
515 | */ |
||
516 | 4 | public function removeHtmlAttribute($htmlAttribute) |
|
520 | } |
||
521 |