Complex classes like Gmap_Core 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 Gmap_Core, and based on these observations, apply Extract Interface, too.
| 1 | <?php defined('SYSPATH') or die('No direct access allowed.'); |
||
| 12 | class Gmap_Core |
||
| 13 | { |
||
| 14 | |||
| 15 | // Map settings |
||
| 16 | protected $id; |
||
| 17 | protected $options; |
||
| 18 | protected $center; |
||
| 19 | protected $control; |
||
| 20 | protected $overview_control; |
||
| 21 | protected $type_control = false; |
||
| 22 | |||
| 23 | // Map types |
||
| 24 | protected $types = array(); |
||
| 25 | protected $default_types = array( |
||
| 26 | 'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP' |
||
| 27 | ); |
||
| 28 | |||
| 29 | // Markers icons |
||
| 30 | protected $icons = array(); |
||
| 31 | |||
| 32 | // Map markers |
||
| 33 | protected $markers = array(); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Set the GMap center point. |
||
| 37 | * |
||
| 38 | * @param string $id HTML map id attribute |
||
| 39 | * @param array $options array of GMap constructor options |
||
|
|
|||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | public function __construct($id = 'map', $options = null) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Return GMap javascript url |
||
| 51 | * |
||
| 52 | * @param string API component |
||
| 53 | * @param array API parameters |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public static function api_url($component = 'jsapi', $parameters = null, $separator = '&') |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Retrieves the latitude and longitude of an address. |
||
| 78 | * |
||
| 79 | * @param string $address address |
||
| 80 | * @return array longitude, latitude |
||
| 81 | */ |
||
| 82 | public static function address_to_ll($address) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Retrieves the XML geocode address lookup. |
||
| 98 | * ! Results of this method are cached for 1 day. |
||
| 99 | * |
||
| 100 | * @param string $address adress |
||
| 101 | * @return object SimpleXML |
||
| 102 | */ |
||
| 103 | public static function address_to_xml($address) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Returns an image map |
||
| 170 | * |
||
| 171 | * @param integer $lat latitude or an array of marker points |
||
| 172 | * @param integer $lon longitude |
||
| 173 | * @param integer $zoom zoom level (1-19) |
||
| 174 | * @param string $type map type (roadmap or mobile) |
||
| 175 | * @param integer $width map width |
||
| 176 | * @param integer $height map height |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | public static function static_map($lat = 0, $lon = 0, $zoom = 6, $type = null, $width = 300, $height = 300) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Set the GMap center point. |
||
| 213 | * |
||
| 214 | * @chainable |
||
| 215 | * @param float $lat latitude |
||
| 216 | * @param float $lon longitude |
||
| 217 | * @param integer $zoom zoom level (1-19) |
||
| 218 | * @param string $type default map type |
||
| 219 | * @return Gmap_Core |
||
| 220 | */ |
||
| 221 | public function center($lat, $lon, $zoom = 6, $type = 'G_NORMAL_MAP') |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Set the GMap controls size. |
||
| 234 | * |
||
| 235 | * @chainable |
||
| 236 | * @param string $size small or large |
||
| 237 | * @return Gmap_Core |
||
| 238 | */ |
||
| 239 | public function controls($size = null) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Set the GMap overview map. |
||
| 249 | * |
||
| 250 | * @chainable |
||
| 251 | * @param integer $width width |
||
| 252 | * @param integer $height height |
||
| 253 | * @return Gmap_Core |
||
| 254 | */ |
||
| 255 | public function overview($width = '', $height = '') |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Set the GMap type controls. |
||
| 265 | * by default renders G_NORMAL_MAP, G_SATELLITE_MAP, and G_HYBRID_MAP |
||
| 266 | * |
||
| 267 | * @chainable |
||
| 268 | * @param string $type map type |
||
| 269 | * @param string $action add or remove map type |
||
| 270 | * @return Gmap_Core |
||
| 271 | */ |
||
| 272 | public function types($type = null, $action = 'remove') |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Create a custom marker icon |
||
| 286 | * |
||
| 287 | * @chainable |
||
| 288 | * @param string $name icon name |
||
| 289 | * @param array $options icon options |
||
| 290 | * @return Gmap_Core |
||
| 291 | */ |
||
| 292 | public function add_icon($name, array $options) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Set the GMap marker point. |
||
| 302 | * |
||
| 303 | * @chainable |
||
| 304 | * @param float $lat latitude |
||
| 305 | * @param float $lon longitude |
||
| 306 | * @param string $html HTML for info window |
||
| 307 | * @param array $options marker options |
||
| 308 | * @return Gmap_Core |
||
| 309 | */ |
||
| 310 | public function add_marker($lat, $lon, $html = '', $options = array()) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Render the map into GMap Javascript. |
||
| 320 | * |
||
| 321 | * @param string $template template name |
||
| 322 | * @param array $extra extra fields passed to the template |
||
| 323 | * @return string |
||
| 324 | */ |
||
| 325 | public function render($template = 'gmaps/javascript', $extra = array()) |
||
| 366 | } // End Gmap |
||
| 367 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
arrayand suggests a stricter type likearray<String>.Most often this is a case of a parameter that can be null in addition to its declared types.