Complex classes like MapAPI 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 MapAPI, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class MapAPI extends Control |
||
| 21 | { |
||
| 22 | |||
| 23 | const ROADMAP = 'ROADMAP', SATELLITE = 'SATELLITE', HYBRID = 'HYBRID', TERRAIN = 'TERRAIN', |
||
| 24 | BICYCLING = 'BICYCLING', DRIVING = 'DRIVING', TRANSIT = 'TRANSIT', WALKING = 'WALKING'; |
||
| 25 | |||
| 26 | /** @var double|string */ |
||
| 27 | private $width; |
||
| 28 | |||
| 29 | /** @var double|string */ |
||
| 30 | private $height; |
||
| 31 | |||
| 32 | /** @var array */ |
||
| 33 | private $coordinates; |
||
| 34 | |||
| 35 | /** @var Integer */ |
||
| 36 | private $zoom; |
||
| 37 | |||
| 38 | /** @var String */ |
||
| 39 | private $type; |
||
| 40 | |||
| 41 | /** @var Boolean */ |
||
| 42 | private $staticMap = FALSE; |
||
| 43 | |||
| 44 | /** @var Boolean */ |
||
| 45 | private $clickable = FALSE; |
||
| 46 | |||
| 47 | /** @var String */ |
||
| 48 | private $key; |
||
| 49 | |||
| 50 | /** @var array */ |
||
| 51 | private $markers = array(); |
||
| 52 | |||
| 53 | /** @var boolean */ |
||
| 54 | private $bound; |
||
| 55 | |||
| 56 | /** @var boolean */ |
||
| 57 | private $markerClusterer; |
||
| 58 | |||
| 59 | /** @var array */ |
||
| 60 | private $clusterOptions; |
||
| 61 | |||
| 62 | /** @var boolean */ |
||
| 63 | private $scrollable = FALSE; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | private $waypoints; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | private $direction = ['travelmode' => 'DRIVING']; |
||
| 76 | |||
| 77 | |||
| 78 | public function __construct() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @internal |
||
| 85 | * @param array $config |
||
| 86 | */ |
||
| 87 | public function setup(array $config) |
||
| 92 | |||
| 93 | |||
| 94 | /** |
||
| 95 | * |
||
| 96 | * @param array $coordinates (latitude, longitude) - center of the map |
||
| 97 | * @return \Oli\GoogleAPI\MapAPI |
||
| 98 | */ |
||
| 99 | public function setCoordinates(array $coordinates) |
||
| 111 | |||
| 112 | |||
| 113 | /** |
||
| 114 | * @param double|string $width |
||
| 115 | * @param double|string $height |
||
| 116 | * @return MapAPI |
||
| 117 | */ |
||
| 118 | public function setProportions($width, $height) |
||
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * |
||
| 128 | * @param string $key |
||
| 129 | * @return \Oli\GoogleAPI\MapAPI |
||
| 130 | */ |
||
| 131 | public function setKey($key) |
||
| 136 | |||
| 137 | |||
| 138 | /** |
||
| 139 | * |
||
| 140 | * @param int $zoom <0, 19> |
||
| 141 | * @return \Oli\GoogleAPI\MapAPI |
||
| 142 | * @throws \InvalidArgumentException |
||
| 143 | * @throws \LogicException |
||
| 144 | */ |
||
| 145 | public function setZoom($zoom) |
||
| 160 | |||
| 161 | |||
| 162 | /** |
||
| 163 | * |
||
| 164 | * @param String $type |
||
| 165 | * @return \Oli\GoogleAPI\MapAPI |
||
| 166 | */ |
||
| 167 | public function setType($type) |
||
| 177 | |||
| 178 | |||
| 179 | public function setWaypoint($key, $waypoint) |
||
| 191 | |||
| 192 | |||
| 193 | public function setDirection(array $direction) |
||
| 202 | |||
| 203 | |||
| 204 | /** |
||
| 205 | * @return array Width and Height of the map. |
||
| 206 | */ |
||
| 207 | public function getProportions() |
||
| 211 | |||
| 212 | |||
| 213 | /** |
||
| 214 | * @return array Center of the map |
||
| 215 | */ |
||
| 216 | public function getCoordinates() |
||
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * @return integer Zoom |
||
| 224 | */ |
||
| 225 | public function getZoom() |
||
| 229 | |||
| 230 | |||
| 231 | /** |
||
| 232 | * @return String Which map type will be show |
||
| 233 | */ |
||
| 234 | public function getType() |
||
| 238 | |||
| 239 | |||
| 240 | public function getKey() |
||
| 244 | |||
| 245 | |||
| 246 | /** |
||
| 247 | * |
||
| 248 | * @param Boolean $staticMap |
||
| 249 | * @return \Oli\GoogleAPI\MapAPI |
||
| 250 | * @throws \InvalidArgumentException |
||
| 251 | */ |
||
| 252 | public function isStaticMap($staticMap = TRUE) |
||
| 262 | |||
| 263 | |||
| 264 | public function getIsStaticMap() |
||
| 268 | |||
| 269 | |||
| 270 | /** |
||
| 271 | * |
||
| 272 | * @param Boolean $clickable |
||
| 273 | * @return \Oli\GoogleAPI\MapAPI |
||
| 274 | * @throws \InvalidArgumentException |
||
| 275 | */ |
||
| 276 | public function isClickable($clickable = TRUE) |
||
| 291 | |||
| 292 | |||
| 293 | public function getIsClicable() |
||
| 297 | |||
| 298 | |||
| 299 | public function isScrollable($scrollable = TRUE) |
||
| 309 | |||
| 310 | |||
| 311 | public function getIsScrollable() |
||
| 315 | |||
| 316 | |||
| 317 | /** |
||
| 318 | * |
||
| 319 | * @param \Oli\GoogleAPI\Markers $markers |
||
| 320 | * @return \Oli\GoogleAPI\MapAPI |
||
| 321 | */ |
||
| 322 | public function addMarkers(Markers $markers) |
||
| 330 | |||
| 331 | |||
| 332 | /** |
||
| 333 | * Alias to handleMarkers() |
||
| 334 | */ |
||
| 335 | public function invalidateMarkers() |
||
| 339 | |||
| 340 | |||
| 341 | /** |
||
| 342 | * @see Nette\Application\Control#render() |
||
| 343 | */ |
||
| 344 | public function render() |
||
| 375 | |||
| 376 | |||
| 377 | /** |
||
| 378 | * Send markers to template as JSON |
||
| 379 | * @internal |
||
| 380 | */ |
||
| 381 | public function handleMarkers() |
||
| 385 | } |
||
| 386 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.