Complex classes like GoogleMap 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 GoogleMap, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class GoogleMap extends ViewableData |
||
|
|||
20 | { |
||
21 | |||
22 | |||
23 | |||
24 | ################################ |
||
25 | # SETTINGS |
||
26 | ################################ |
||
27 | |||
28 | |||
29 | /* BASIC MAP SETTINGS */ |
||
30 | private static $api_version = '3'; |
||
31 | private static $google_map_api_key = ""; |
||
32 | private static $default_latitude = 0.000000001; //MOVE TO SITECONFIG |
||
33 | private static $default_longitude = 0.0000000001; //MOVE TO SITECONFIG |
||
34 | private static $default_zoom = 2; //MOVE TO SITECONFIG |
||
35 | private static $google_map_width = 0; |
||
36 | private static $google_map_height = 0; |
||
37 | |||
38 | /* MAP CONTROLS*/ |
||
39 | private static $map_type_default = 0; //MOVE TO SITECONFIG |
||
40 | private static $view_finder_size = 100; //MOVE TO SITECONFIG |
||
41 | private static $map_add_type_control = false; //MOVE TO SITECONFIG |
||
42 | private static $map_control_size_one_to_three = 3; //MOVE TO SITECONFIG |
||
43 | private static $map_scale_info_size_in_pixels = 100; //MOVE TO SITECONFIG |
||
44 | |||
45 | /* INFORMATION AROUND THE MAP */ |
||
46 | private static $default_title = ""; //MOVE TO SITECONFIG |
||
47 | private static $default_where_statement_description = ""; //MOVE TO SITECONFIG |
||
48 | private static $no_status_at_all = true; //MOVE TO SITECONFIG |
||
49 | private static $add_kml_link = false; //MOVE TO SITECONFIG |
||
50 | private static $hidden_layers_removed_from_list = false; |
||
51 | private static $change_page_title = false; //MOVE TO SITECONFIG |
||
52 | private static $number_of_items_before_showing_list = 1; //MOVE TO SITECONFIG |
||
53 | private static $main_div_id = "GoogleMapDiv"; |
||
54 | private static $title_div_id = ""; |
||
55 | private static $side_bar_div_id = ""; |
||
56 | private static $drop_down_div_id =""; |
||
57 | private static $layer_list_div_id = ""; |
||
58 | private static $directions_div_id = ""; |
||
59 | private static $status_div_id = ""; |
||
60 | |||
61 | /* INFOWINDOW*/ |
||
62 | private static $info_window_options = "{maxWidth:280, zoomLevel:17, mapTypeId: google.maps.MapTypeId.HYBRID}"; |
||
63 | private static $add_antipodean = false; //MOVE TO SITECONFIG |
||
64 | private static $add_directions = false; //MOVE TO SITECONFIG |
||
65 | private static $add_current_address_finder_in_marker = false; //MOVE TO SITECONFIG |
||
66 | private static $add_zoom_in_button = true; //MOVE TO SITECONFIG |
||
67 | private static $ajax_info_window_text = "View Details"; //MOVE TO SITECONFIG |
||
68 | |||
69 | /* MARKERS */ |
||
70 | private static $add_points_to_map = false; |
||
71 | private static $add_delete_marker_button = ""; |
||
72 | private static $marker_options = "{bouncy:true,title: \"click me\"}"; |
||
73 | private static $preload_images = false; |
||
74 | |||
75 | /* ICONS */ |
||
76 | private static $default_icon_url = ""; |
||
77 | private static $icon_folder = "/googlemap/images/icons/"; |
||
78 | private static $icon_width = 20; |
||
79 | private static $icon_height = 34; |
||
80 | private static $icon_extension = "png"; |
||
81 | private static $icon_max_count = 12; |
||
82 | |||
83 | /* POLYS */ |
||
84 | private static $line_colour = "#000"; |
||
85 | private static $line_width = 12; |
||
86 | private static $line_opacity = 0.5; |
||
87 | private static $fill_colour = "#ffccff"; |
||
88 | private static $fill_opacity = 0.5; |
||
89 | private static $poly_icon = ""; |
||
90 | |||
91 | /* STATIC MAP */ |
||
92 | private static $static_map_settings = "maptype=roadmap"; |
||
93 | private static $static_icon = ""; |
||
94 | private static $save_static_map_locally = false; |
||
95 | |||
96 | /* ADDRESS FINDER */ |
||
97 | private static $add_address_finder = false; //MOVE TO SITECONFIG |
||
98 | private static $default_country_code = "nz"; // see https://developers.google.com/maps/documentation/geocoding/#RegionCodes |
||
99 | private static $number_shown_in_around_me = 7; //MOVE TO SITECONFIG |
||
100 | private static $max_radius_for_show_around_me = 20000; |
||
101 | |||
102 | /* DIRECTIONS SETTINGS */ |
||
103 | private static $style_sheet_url = ""; |
||
104 | private static $locale_for_results = "en_NZ"; |
||
105 | |||
106 | /* SERVER SETTINGS */ |
||
107 | private static $lng_form_field_id = ""; |
||
108 | private static $lat_form_field_id = ""; |
||
109 | |||
110 | |||
111 | |||
112 | |||
113 | |||
114 | |||
115 | |||
116 | |||
117 | |||
118 | |||
119 | ################################ |
||
120 | # TEMPATE METHODS |
||
121 | ################################ |
||
122 | |||
123 | /** |
||
124 | * @return String |
||
125 | */ |
||
126 | public function Link() |
||
133 | |||
134 | |||
135 | /** |
||
136 | * function name for map... |
||
137 | * @var String |
||
138 | */ |
||
139 | protected $myMapFunctionName = "GMO"; |
||
140 | public function setMyMapFunctionName($a) |
||
161 | |||
162 | /** |
||
163 | * title of map |
||
164 | * @var string |
||
165 | */ |
||
166 | protected $titleOfMap = ""; |
||
167 | |||
168 | public function setTitleOfMap($s) |
||
180 | |||
181 | /** |
||
182 | * title of map |
||
183 | * @var string |
||
184 | */ |
||
185 | protected $noDataPointsMessage = ""; |
||
186 | |||
187 | public function setNoDataPointsMessage($s) |
||
199 | |||
200 | |||
201 | /** |
||
202 | * used for static and non-static maps, hence defined only once. |
||
203 | * @return Int |
||
204 | */ |
||
205 | public function GoogleMapWidth() |
||
209 | |||
210 | /** |
||
211 | * used for static and non-static maps, hence defined only once. |
||
212 | * @return Int |
||
213 | */ |
||
214 | public function GoogleMapHeight() |
||
218 | |||
219 | /** |
||
220 | * @return Boolean |
||
221 | */ |
||
222 | public function AddAddressFinder() |
||
226 | |||
227 | /** |
||
228 | * @return Boolean |
||
229 | */ |
||
230 | public function CanEdit($member = null) |
||
238 | |||
239 | /** |
||
240 | * @return String |
||
241 | */ |
||
242 | public function TitleDivID() |
||
246 | |||
247 | /** |
||
248 | * @return String |
||
249 | */ |
||
250 | public function SideBarDivId() |
||
254 | |||
255 | /** |
||
256 | * @return String |
||
257 | */ |
||
258 | public function DropDownDivId() |
||
262 | |||
263 | /** |
||
264 | * @return String |
||
265 | */ |
||
266 | public function LayerListDivId() |
||
270 | |||
271 | /** |
||
272 | * @return String |
||
273 | */ |
||
274 | public function DirectionsDivId() |
||
278 | |||
279 | /** |
||
280 | * @return String |
||
281 | */ |
||
282 | public function StatusDivId() |
||
286 | |||
287 | /** |
||
288 | * |
||
289 | * @var Boolean |
||
290 | */ |
||
291 | public function AllowAddPointsToMap() |
||
295 | |||
296 | /** |
||
297 | * @var ArrayList |
||
298 | */ |
||
299 | protected $processedDataPointsForTemplate = null; |
||
300 | public function setProcessedDataPointsForTemplate($s) |
||
312 | |||
313 | /** |
||
314 | * @var string |
||
315 | */ |
||
316 | protected $dataPointsXML = ''; |
||
317 | protected function DataPointsXML() |
||
326 | |||
327 | |||
328 | |||
329 | |||
330 | |||
331 | |||
332 | |||
333 | |||
334 | |||
335 | |||
336 | |||
337 | ################################ |
||
338 | # SETUP: LAYER MANAGEMENT |
||
339 | ################################ |
||
340 | |||
341 | |||
342 | |||
343 | |||
344 | /** |
||
345 | * @var ArrayList |
||
346 | */ |
||
347 | protected $extraLayers = null; |
||
348 | public function setExtraLayer($a) |
||
356 | |||
357 | /** |
||
358 | * @param String $title |
||
359 | * @param String $link |
||
360 | */ |
||
361 | public function addExtraLayer($title, $link) |
||
376 | |||
377 | /** |
||
378 | * |
||
379 | * @return ArrayList |
||
380 | */ |
||
381 | public function AllExtraLayers() |
||
385 | |||
386 | /** |
||
387 | * @var Array |
||
388 | * Link => Title |
||
389 | */ |
||
390 | protected $linksForData = array(); |
||
391 | public function setLinksForData($a) |
||
399 | |||
400 | /** |
||
401 | * @param string $linkForData |
||
402 | * @param string $title |
||
403 | */ |
||
404 | public function addLayer($linkForData, $title) |
||
408 | |||
409 | |||
410 | |||
411 | |||
412 | |||
413 | |||
414 | |||
415 | ################################ |
||
416 | # SETUP: FILTERS AND POINTS PROVIDERS |
||
417 | ################################ |
||
418 | |||
419 | /** |
||
420 | * address being searched for |
||
421 | * @var String |
||
422 | */ |
||
423 | protected $address = ""; |
||
424 | public function setAddress($v) |
||
432 | |||
433 | /** |
||
434 | * sets the list of points through a list of parent pages |
||
435 | * affected variable is: points |
||
436 | * @param DataList | ArrayList $pageDataList |
||
437 | */ |
||
438 | public function setPageDataObjectSet($pageDataList) |
||
452 | |||
453 | |||
454 | /** |
||
455 | * @var DataList |
||
456 | */ |
||
457 | protected $points = null; |
||
458 | public function setPoints($s) |
||
466 | |||
467 | |||
468 | |||
469 | /** |
||
470 | * a description of how the points were selected ... |
||
471 | * @var String |
||
472 | */ |
||
473 | protected $whereStatementDescription = ""; |
||
474 | public function setWhereStatementDescription($s) |
||
482 | |||
483 | /** |
||
484 | * filter for class names |
||
485 | * @var Array |
||
486 | */ |
||
487 | protected $filteredClassNameArray = array(); |
||
488 | public function setFilteredClassNameArray($a) |
||
496 | |||
497 | |||
498 | |||
499 | |||
500 | |||
501 | |||
502 | |||
503 | ################################ |
||
504 | # MAP CHANGES |
||
505 | ################################ |
||
506 | |||
507 | /** |
||
508 | * @var String |
||
509 | */ |
||
510 | protected $updateServerUrlAddressSearchPoint = "/googlemap/showaroundmexml/"; |
||
511 | public function setUpdateServerUrlAddressSearchPoint($v) |
||
519 | |||
520 | /** |
||
521 | * @var String |
||
522 | */ |
||
523 | protected $updateServerUrlDragend = ""; |
||
524 | public function setUpdateServerUrlDragend($v) |
||
532 | |||
533 | |||
534 | |||
535 | |||
536 | |||
537 | |||
538 | |||
539 | |||
540 | |||
541 | |||
542 | ################################ |
||
543 | # LOADING |
||
544 | ################################ |
||
545 | /** |
||
546 | * this is a hack to avoid having multiple includes |
||
547 | * @var Boolean |
||
548 | */ |
||
549 | private static $_includes_are_done = false; |
||
550 | |||
551 | public function loadGoogleMap() |
||
576 | |||
577 | |||
578 | |||
579 | |||
580 | |||
581 | |||
582 | |||
583 | ################################ |
||
584 | # DATA POINTS MASSAGE |
||
585 | ################################ |
||
586 | |||
587 | /** |
||
588 | * sorts points by Latitude |
||
589 | * @param boolean $reverse |
||
590 | * |
||
591 | * @return ArrayList |
||
592 | */ |
||
593 | protected function orderItemsByLatitude($reverse = false) |
||
613 | |||
614 | /** |
||
615 | * |
||
616 | * @return Int |
||
617 | */ |
||
618 | public function getPointCount() |
||
627 | |||
628 | /** |
||
629 | * @return Boolean |
||
630 | */ |
||
631 | public function EnoughPointsForAList() |
||
635 | |||
636 | |||
637 | /** |
||
638 | * must be public |
||
639 | * does not return the datapoints XML |
||
640 | * but loads it into variables... |
||
641 | * @return Boolean |
||
642 | */ |
||
643 | public function createDataPoints() |
||
727 | |||
728 | /** |
||
729 | * @param String staticVariablename |
||
730 | * @return String (Javascript) |
||
731 | */ |
||
732 | protected function createJavascript() |
||
834 | |||
835 | /** |
||
836 | * turns 0 into false and 1 into true |
||
837 | * @param Mixed |
||
838 | * @return string (true|false) |
||
839 | */ |
||
840 | protected function showFalseOrTrue($v) |
||
848 | |||
849 | /** |
||
850 | * load some defaults |
||
851 | */ |
||
852 | protected function loadDefaults() |
||
861 | } |
||
862 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.