Complex classes like OverlayManager 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 OverlayManager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class OverlayManager |
||
20 | { |
||
21 | /** |
||
22 | * @var Map|null |
||
23 | */ |
||
24 | private $map; |
||
25 | |||
26 | /** |
||
27 | * @var MarkerCluster |
||
28 | */ |
||
29 | private $markerCluster; |
||
30 | |||
31 | /** |
||
32 | * @var InfoWindow[] |
||
33 | */ |
||
34 | private $infoWindows = []; |
||
35 | |||
36 | /** |
||
37 | * @var Polyline[] |
||
38 | */ |
||
39 | private $polylines = []; |
||
40 | |||
41 | /** |
||
42 | * @var EncodedPolyline[] |
||
43 | */ |
||
44 | private $encodedPolylines = []; |
||
45 | |||
46 | /** |
||
47 | * @var Polygon[] |
||
48 | */ |
||
49 | private $polygons = []; |
||
50 | |||
51 | /** |
||
52 | * @var Rectangle[] |
||
53 | */ |
||
54 | private $rectangles = []; |
||
55 | |||
56 | /** |
||
57 | * @var Circle[] |
||
58 | */ |
||
59 | private $circles = []; |
||
60 | |||
61 | /** |
||
62 | * @var GroundOverlay[] |
||
63 | */ |
||
64 | private $groundOverlays = []; |
||
65 | |||
66 | 644 | public function __construct() |
|
70 | |||
71 | /** |
||
72 | * @return bool |
||
73 | */ |
||
74 | 332 | public function hasMap() |
|
78 | |||
79 | /** |
||
80 | * @return Map|null |
||
81 | */ |
||
82 | 612 | public function getMap() |
|
86 | |||
87 | 644 | public function setMap(Map $map) |
|
95 | |||
96 | /** |
||
97 | * @return MarkerCluster |
||
98 | */ |
||
99 | 644 | public function getMarkerCluster() |
|
103 | |||
104 | 644 | public function setMarkerCluster(MarkerCluster $markerCluster) |
|
112 | |||
113 | /** |
||
114 | * @return bool |
||
115 | */ |
||
116 | 8 | public function hasMarkers() |
|
120 | |||
121 | /** |
||
122 | * @return Marker[] |
||
123 | */ |
||
124 | 108 | public function getMarkers() |
|
128 | |||
129 | /** |
||
130 | * @param Marker[] $markers |
||
131 | */ |
||
132 | 4 | public function setMarkers(array $markers) |
|
136 | |||
137 | /** |
||
138 | * @param Marker[] $markers |
||
139 | */ |
||
140 | 4 | public function addMarkers(array $markers) |
|
144 | |||
145 | /** |
||
146 | * @return bool |
||
147 | */ |
||
148 | 4 | public function hasMarker(Marker $marker) |
|
152 | |||
153 | 36 | public function addMarker(Marker $marker) |
|
157 | |||
158 | 4 | public function removeMarker(Marker $marker) |
|
162 | |||
163 | /** |
||
164 | * @return bool |
||
165 | */ |
||
166 | 32 | public function hasInfoWindows() |
|
170 | |||
171 | /** |
||
172 | * @return InfoWindow[] |
||
173 | */ |
||
174 | 104 | public function getInfoWindows() |
|
178 | |||
179 | /** |
||
180 | * @param InfoWindow[] $infoWindows |
||
181 | */ |
||
182 | 16 | public function setInfoWindows(array $infoWindows) |
|
190 | |||
191 | /** |
||
192 | * @param InfoWindow[] $infoWindows |
||
193 | */ |
||
194 | 16 | public function addInfoWindows(array $infoWindows) |
|
200 | |||
201 | /** |
||
202 | * @return bool |
||
203 | */ |
||
204 | 40 | public function hasInfoWindow(InfoWindow $infoWindow) |
|
208 | |||
209 | 40 | public function addInfoWindow(InfoWindow $infoWindow) |
|
217 | |||
218 | 16 | public function removeInfoWindow(InfoWindow $infoWindow) |
|
224 | |||
225 | /** |
||
226 | * @return bool |
||
227 | */ |
||
228 | 32 | public function hasPolylines() |
|
232 | |||
233 | /** |
||
234 | * @return Polyline[] |
||
235 | */ |
||
236 | 84 | public function getPolylines() |
|
240 | |||
241 | /** |
||
242 | * @param Polyline[] $polylines |
||
243 | */ |
||
244 | 16 | public function setPolylines(array $polylines) |
|
252 | |||
253 | /** |
||
254 | * @param Polyline[] $polylines |
||
255 | */ |
||
256 | 16 | public function addPolylines(array $polylines) |
|
262 | |||
263 | /** |
||
264 | * @return bool |
||
265 | */ |
||
266 | 52 | public function hasPolyline(Polyline $polyline) |
|
270 | |||
271 | 52 | public function addPolyline(Polyline $polyline) |
|
279 | |||
280 | 16 | public function removePolyline(Polyline $polyline) |
|
286 | |||
287 | /** |
||
288 | * @return bool |
||
289 | */ |
||
290 | 32 | public function hasEncodedPolylines() |
|
294 | |||
295 | /** |
||
296 | * @return EncodedPolyline[] |
||
297 | */ |
||
298 | 40 | public function getEncodedPolylines() |
|
302 | |||
303 | /** |
||
304 | * @param EncodedPolyline[] $encodedPolylines |
||
305 | */ |
||
306 | 16 | public function setEncodedPolylines(array $encodedPolylines) |
|
314 | |||
315 | /** |
||
316 | * @param EncodedPolyline[] $encodedPolylines |
||
317 | */ |
||
318 | 16 | public function addEncodedPolylines(array $encodedPolylines) |
|
324 | |||
325 | /** |
||
326 | * @return bool |
||
327 | */ |
||
328 | 40 | public function hasEncodedPolyline(EncodedPolyline $encodedPolyline) |
|
332 | |||
333 | 40 | public function addEncodedPolyline(EncodedPolyline $encodedPolyline) |
|
341 | |||
342 | 16 | public function removeEncodedPolyline(EncodedPolyline $encodedPolyline) |
|
348 | |||
349 | /** |
||
350 | * @return bool |
||
351 | */ |
||
352 | 32 | public function hasPolygons() |
|
356 | |||
357 | /** |
||
358 | * @return Polygon[] |
||
359 | */ |
||
360 | 72 | public function getPolygons() |
|
364 | |||
365 | /** |
||
366 | * @param Polygon[] $polygons |
||
367 | */ |
||
368 | 16 | public function setPolygons(array $polygons) |
|
376 | |||
377 | /** |
||
378 | * @param Polygon[] $polygons |
||
379 | */ |
||
380 | 16 | public function addPolygons(array $polygons) |
|
386 | |||
387 | /** |
||
388 | * @return bool |
||
389 | */ |
||
390 | 40 | public function hasPolygon(Polygon $polygon) |
|
394 | |||
395 | 40 | public function addPolygon(Polygon $polygon) |
|
403 | |||
404 | 16 | public function removePolygon(Polygon $polygon) |
|
410 | |||
411 | /** |
||
412 | * @return bool |
||
413 | */ |
||
414 | 32 | public function hasRectangles() |
|
418 | |||
419 | /** |
||
420 | * @return Rectangle[] |
||
421 | */ |
||
422 | 88 | public function getRectangles() |
|
426 | |||
427 | /** |
||
428 | * @param Rectangle[] $rectangles |
||
429 | */ |
||
430 | 16 | public function setRectangles(array $rectangles) |
|
438 | |||
439 | /** |
||
440 | * @param Rectangle[] $rectangles |
||
441 | */ |
||
442 | 16 | public function addRectangles(array $rectangles) |
|
448 | |||
449 | /** |
||
450 | * @return bool |
||
451 | */ |
||
452 | 44 | public function hasRectangle(Rectangle $rectangle) |
|
456 | |||
457 | 44 | public function addRectangle(Rectangle $rectangle) |
|
465 | |||
466 | 16 | public function removeRectangle(Rectangle $rectangle) |
|
472 | |||
473 | /** |
||
474 | * @return bool |
||
475 | */ |
||
476 | 32 | public function hasCircles() |
|
480 | |||
481 | /** |
||
482 | * @return Circle[] |
||
483 | */ |
||
484 | 72 | public function getCircles() |
|
488 | |||
489 | /** |
||
490 | * @param Circle[] $circles |
||
491 | */ |
||
492 | 16 | public function setCircles(array $circles) |
|
500 | |||
501 | /** |
||
502 | * @param Circle[] $circles |
||
503 | */ |
||
504 | 16 | public function addCircles(array $circles) |
|
510 | |||
511 | /** |
||
512 | * @return bool |
||
513 | */ |
||
514 | 40 | public function hasCircle(Circle $circle) |
|
518 | |||
519 | 40 | public function addCircle(Circle $circle) |
|
527 | |||
528 | 16 | public function removeCircle(Circle $circle) |
|
534 | |||
535 | /** |
||
536 | * @return bool |
||
537 | */ |
||
538 | 32 | public function hasGroundOverlays() |
|
542 | |||
543 | /** |
||
544 | * @return GroundOverlay[] |
||
545 | */ |
||
546 | 88 | public function getGroundOverlays() |
|
550 | |||
551 | /** |
||
552 | * @param GroundOverlay[] $groundOverlays |
||
553 | */ |
||
554 | 16 | public function setGroundOverlays(array $groundOverlays) |
|
562 | |||
563 | /** |
||
564 | * @param GroundOverlay[] $groundOverlays |
||
565 | */ |
||
566 | 16 | public function addGroundOverlays(array $groundOverlays) |
|
572 | |||
573 | /** |
||
574 | * @return bool |
||
575 | */ |
||
576 | 40 | public function hasGroundOverlay(GroundOverlay $groundOverlay) |
|
580 | |||
581 | 40 | public function addGroundOverlay(GroundOverlay $groundOverlay) |
|
589 | |||
590 | 16 | public function removeGroundOverlay(GroundOverlay $groundOverlay) |
|
596 | |||
597 | 296 | private function addExtendable(ExtendableInterface $extendable) |
|
603 | |||
604 | 112 | private function removeExtendable(ExtendableInterface $extendable) |
|
610 | |||
611 | /** |
||
612 | * @return bool |
||
613 | */ |
||
614 | 296 | private function isAutoZoom() |
|
618 | } |
||
619 |