Complex classes like Map 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 Map, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Map implements VariableAwareInterface |
||
| 29 | { |
||
| 30 | use VariableAwareTrait; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | private $htmlId = 'map_canvas'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var bool |
||
| 39 | */ |
||
| 40 | private $autoZoom = false; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var Coordinate |
||
| 44 | */ |
||
| 45 | private $center; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var Bound |
||
| 49 | */ |
||
| 50 | private $bound; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var ControlManager |
||
| 54 | */ |
||
| 55 | private $controlManager; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var EventManager |
||
| 59 | */ |
||
| 60 | private $eventManager; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var LayerManager |
||
| 64 | */ |
||
| 65 | private $layerManager; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var OverlayManager |
||
| 69 | */ |
||
| 70 | private $overlayManager; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string[] |
||
| 74 | */ |
||
| 75 | private $libraries = []; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var mixed[] |
||
| 79 | */ |
||
| 80 | private $mapOptions = []; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var string[] |
||
| 84 | */ |
||
| 85 | private $stylesheetOptions = []; |
||
| 86 | |||
| 87 | public function __construct() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public function getHtmlId() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param string $htmlId |
||
| 108 | */ |
||
| 109 | public function setHtmlId($htmlId) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return bool |
||
| 116 | */ |
||
| 117 | public function isAutoZoom() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param bool $autoZoom |
||
| 124 | */ |
||
| 125 | public function setAutoZoom($autoZoom) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return Coordinate |
||
| 132 | */ |
||
| 133 | public function getCenter() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param Coordinate $center |
||
| 140 | */ |
||
| 141 | public function setCenter(Coordinate $center) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return Bound |
||
| 148 | */ |
||
| 149 | public function getBound() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param Bound $bound |
||
| 156 | */ |
||
| 157 | public function setBound(Bound $bound) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return ControlManager |
||
| 164 | */ |
||
| 165 | public function getControlManager() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param ControlManager $controlManager |
||
| 172 | */ |
||
| 173 | public function setControlManager(ControlManager $controlManager) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return EventManager |
||
| 180 | */ |
||
| 181 | public function getEventManager() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param EventManager $eventManager |
||
| 188 | */ |
||
| 189 | public function setEventManager(EventManager $eventManager) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return LayerManager |
||
| 196 | */ |
||
| 197 | public function getLayerManager() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param LayerManager $layerManager |
||
| 204 | */ |
||
| 205 | public function setLayerManager(LayerManager $layerManager) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return OverlayManager |
||
| 212 | */ |
||
| 213 | public function getOverlayManager() |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param OverlayManager $overlayManager |
||
| 220 | */ |
||
| 221 | public function setOverlayManager(OverlayManager $overlayManager) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return bool |
||
| 232 | */ |
||
| 233 | public function hasLibraries() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @return string[] |
||
| 240 | */ |
||
| 241 | public function getLibraries() |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @param string[] $libraries |
||
| 248 | */ |
||
| 249 | public function setLibraries(array $libraries) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param string[] $libraries |
||
| 257 | */ |
||
| 258 | public function addLibraries(array $libraries) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param string $library |
||
| 267 | * |
||
| 268 | * @return bool |
||
| 269 | */ |
||
| 270 | public function hasLibrary($library) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param string $library |
||
| 277 | */ |
||
| 278 | public function addLibrary($library) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param string $library |
||
| 287 | */ |
||
| 288 | public function removeLibrary($library) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return bool |
||
| 295 | */ |
||
| 296 | public function hasMapOptions() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return mixed[] |
||
| 303 | */ |
||
| 304 | public function getMapOptions() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param mixed[] $mapOptions |
||
| 311 | */ |
||
| 312 | public function setMapOptions(array $mapOptions) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param mixed[] $mapOptions |
||
| 320 | */ |
||
| 321 | public function addMapOptions(array $mapOptions) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @param string $mapOption |
||
| 330 | * |
||
| 331 | * @return bool |
||
| 332 | */ |
||
| 333 | public function hasMapOption($mapOption) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $mapOption |
||
| 340 | * |
||
| 341 | * @return mixed |
||
| 342 | */ |
||
| 343 | public function getMapOption($mapOption) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @param string $mapOption |
||
| 350 | * @param mixed $value |
||
| 351 | */ |
||
| 352 | public function setMapOption($mapOption, $value) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @param string $mapOption |
||
| 359 | */ |
||
| 360 | public function removeMapOption($mapOption) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @return bool |
||
| 367 | */ |
||
| 368 | public function hasStylesheetOptions() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return string[] |
||
| 375 | */ |
||
| 376 | public function getStylesheetOptions() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param string[] $stylesheetOptions |
||
| 383 | */ |
||
| 384 | public function setStylesheetOptions(array $stylesheetOptions) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @param string[] $stylesheetOptions |
||
| 392 | */ |
||
| 393 | public function addStylesheetOptions(array $stylesheetOptions) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @param string $stylesheetOption |
||
| 402 | * |
||
| 403 | * @return bool |
||
| 404 | */ |
||
| 405 | public function hasStylesheetOption($stylesheetOption) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @param string $stylesheetOption |
||
| 412 | * |
||
| 413 | * @return string|null |
||
| 414 | */ |
||
| 415 | public function getStylesheetOption($stylesheetOption) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @param string $stylesheetOption |
||
| 422 | * @param string $value |
||
| 423 | */ |
||
| 424 | public function setStylesheetOption($stylesheetOption, $value) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param string $stylesheetOption |
||
| 431 | */ |
||
| 432 | public function removeStylesheetOption($stylesheetOption) |
||
| 436 | } |
||
| 437 |