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 string |
||
| 204 | */ |
||
| 205 | public function GoogleMapDivID() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * used for static and non-static maps, hence defined only once. |
||
| 212 | * @return Int |
||
| 213 | */ |
||
| 214 | public function GoogleMapWidth() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * used for static and non-static maps, hence defined only once. |
||
| 221 | * @return Int |
||
| 222 | */ |
||
| 223 | public function GoogleMapHeight() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return Boolean |
||
| 230 | */ |
||
| 231 | public function AddAddressFinder() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @return Boolean |
||
| 238 | */ |
||
| 239 | public function CanEdit($member = null) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @return String |
||
| 250 | */ |
||
| 251 | public function TitleDivID() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @return String |
||
| 258 | */ |
||
| 259 | public function SideBarDivId() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @return String |
||
| 266 | */ |
||
| 267 | public function DropDownDivId() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @return String |
||
| 274 | */ |
||
| 275 | public function LayerListDivId() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @return String |
||
| 282 | */ |
||
| 283 | public function DirectionsDivId() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @return String |
||
| 290 | */ |
||
| 291 | public function StatusDivId() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * |
||
| 298 | * @var Boolean |
||
| 299 | */ |
||
| 300 | public function AllowAddPointsToMap() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @var ArrayList |
||
| 307 | */ |
||
| 308 | protected $processedDataPointsForTemplate = null; |
||
| 309 | public function setProcessedDataPointsForTemplate($s) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @var string |
||
| 324 | */ |
||
| 325 | protected $dataPointsXML = ''; |
||
| 326 | protected function DataPointsXML() |
||
| 335 | |||
| 336 | |||
| 337 | |||
| 338 | |||
| 339 | |||
| 340 | |||
| 341 | |||
| 342 | |||
| 343 | |||
| 344 | |||
| 345 | |||
| 346 | ################################ |
||
| 347 | # SETUP: LAYER MANAGEMENT |
||
| 348 | ################################ |
||
| 349 | |||
| 350 | |||
| 351 | |||
| 352 | |||
| 353 | /** |
||
| 354 | * @var ArrayList |
||
| 355 | */ |
||
| 356 | protected $extraLayers = null; |
||
| 357 | public function setExtraLayer($a) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @param String $title |
||
| 368 | * @param String $link |
||
| 369 | */ |
||
| 370 | public function addExtraLayer($title, $link) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * |
||
| 388 | * @return ArrayList |
||
| 389 | */ |
||
| 390 | public function AllExtraLayers() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @var Array |
||
| 397 | * Link => Title |
||
| 398 | */ |
||
| 399 | protected $linksForData = array(); |
||
| 400 | public function setLinksForData($a) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @param string $linkForData |
||
| 411 | * @param string $title |
||
| 412 | */ |
||
| 413 | public function addLayer($linkForData, $title) |
||
| 417 | |||
| 418 | |||
| 419 | |||
| 420 | |||
| 421 | |||
| 422 | |||
| 423 | |||
| 424 | ################################ |
||
| 425 | # SETUP: FILTERS AND POINTS PROVIDERS |
||
| 426 | ################################ |
||
| 427 | |||
| 428 | /** |
||
| 429 | * address being searched for |
||
| 430 | * @var String |
||
| 431 | */ |
||
| 432 | protected $address = ""; |
||
| 433 | public function setAddress($v) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * sets the list of points through a list of parent pages |
||
| 444 | * affected variable is: points |
||
| 445 | * @param DataList | ArrayList $pageDataList |
||
| 446 | */ |
||
| 447 | public function setPageDataObjectSet($pageDataList) |
||
| 461 | |||
| 462 | |||
| 463 | /** |
||
| 464 | * @var DataList |
||
| 465 | */ |
||
| 466 | protected $points = null; |
||
| 467 | public function setPoints($s) |
||
| 475 | |||
| 476 | |||
| 477 | |||
| 478 | /** |
||
| 479 | * a description of how the points were selected ... |
||
| 480 | * @var String |
||
| 481 | */ |
||
| 482 | protected $whereStatementDescription = ""; |
||
| 483 | public function setWhereStatementDescription($s) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * filter for class names |
||
| 494 | * @var Array |
||
| 495 | */ |
||
| 496 | protected $filteredClassNameArray = array(); |
||
| 497 | public function setFilteredClassNameArray($a) |
||
| 505 | |||
| 506 | |||
| 507 | |||
| 508 | |||
| 509 | |||
| 510 | |||
| 511 | |||
| 512 | ################################ |
||
| 513 | # MAP CHANGES |
||
| 514 | ################################ |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @var String |
||
| 518 | */ |
||
| 519 | protected $updateServerUrlAddressSearchPoint = "/googlemap/showaroundmexml/"; |
||
| 520 | public function setUpdateServerUrlAddressSearchPoint($v) |
||
| 528 | |||
| 529 | /** |
||
| 530 | * @var String |
||
| 531 | */ |
||
| 532 | protected $updateServerUrlDragend = ""; |
||
| 533 | public function setUpdateServerUrlDragend($v) |
||
| 541 | |||
| 542 | |||
| 543 | |||
| 544 | |||
| 545 | |||
| 546 | |||
| 547 | |||
| 548 | |||
| 549 | |||
| 550 | |||
| 551 | ################################ |
||
| 552 | # LOADING |
||
| 553 | ################################ |
||
| 554 | /** |
||
| 555 | * this is a hack to avoid having multiple includes |
||
| 556 | * @var Boolean |
||
| 557 | */ |
||
| 558 | private static $_includes_are_done = false; |
||
| 559 | |||
| 560 | public function loadGoogleMap() |
||
| 585 | |||
| 586 | |||
| 587 | |||
| 588 | |||
| 589 | |||
| 590 | |||
| 591 | |||
| 592 | ################################ |
||
| 593 | # DATA POINTS MASSAGE |
||
| 594 | ################################ |
||
| 595 | |||
| 596 | /** |
||
| 597 | * sorts points by Latitude |
||
| 598 | * @param boolean $reverse |
||
| 599 | * |
||
| 600 | * @return ArrayList |
||
| 601 | */ |
||
| 602 | protected function orderItemsByLatitude($reverse = false) |
||
| 622 | |||
| 623 | /** |
||
| 624 | * |
||
| 625 | * @return Int |
||
| 626 | */ |
||
| 627 | public function getPointCount() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * @return Boolean |
||
| 639 | */ |
||
| 640 | public function EnoughPointsForAList() |
||
| 644 | |||
| 645 | |||
| 646 | /** |
||
| 647 | * must be public |
||
| 648 | * does not return the datapoints XML |
||
| 649 | * but loads it into variables... |
||
| 650 | * @return Boolean |
||
| 651 | */ |
||
| 652 | public function createDataPoints() |
||
| 736 | |||
| 737 | /** |
||
| 738 | * @param String staticVariablename |
||
| 739 | * @return String (Javascript) |
||
| 740 | */ |
||
| 741 | protected function createJavascript() |
||
| 843 | |||
| 844 | /** |
||
| 845 | * turns 0 into false and 1 into true |
||
| 846 | * @param Mixed |
||
| 847 | * @return string (true|false) |
||
| 848 | */ |
||
| 849 | protected function showFalseOrTrue($v) |
||
| 857 | |||
| 858 | /** |
||
| 859 | * load some defaults |
||
| 860 | */ |
||
| 861 | protected function loadDefaults() |
||
| 870 | } |
||
| 871 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.