Complex classes like LayerManager 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 LayerManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class LayerManager |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var Map|null |
||
| 24 | */ |
||
| 25 | private $map; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var GeoJsonLayer[] |
||
| 29 | */ |
||
| 30 | private $geoJsonLayers = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var HeatmapLayer[] |
||
| 34 | */ |
||
| 35 | private $heatmapLayers = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var KmlLayer[] |
||
| 39 | */ |
||
| 40 | private $kmlLayers = []; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | 84 | public function hasMap() |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @return Map|null |
||
| 52 | */ |
||
| 53 | 452 | public function getMap() |
|
| 57 | |||
| 58 | 468 | public function setMap(Map $map) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | 20 | public function hasGeoJsonLayers() |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @return GeoJsonLayer[] |
||
| 77 | */ |
||
| 78 | 24 | public function getGeoJsonLayers() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @param GeoJsonLayer[] $geoJsonLayers |
||
| 85 | */ |
||
| 86 | 8 | public function setGeoJsonLayers(array $geoJsonLayers) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param GeoJsonLayer[] $geoJsonLayers |
||
| 94 | */ |
||
| 95 | 8 | public function addGeoJsonLayers(array $geoJsonLayers) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * @return bool |
||
| 104 | */ |
||
| 105 | 20 | public function hasGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
|
| 109 | |||
| 110 | 20 | public function addGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
|
| 116 | |||
| 117 | 4 | public function removeGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
|
| 122 | |||
| 123 | /** |
||
| 124 | * @return bool |
||
| 125 | */ |
||
| 126 | 36 | public function hasHeatmapLayers() |
|
| 130 | |||
| 131 | /** |
||
| 132 | * @return HeatmapLayer[] |
||
| 133 | */ |
||
| 134 | 76 | public function getHeatmapLayers() |
|
| 138 | |||
| 139 | /** |
||
| 140 | * @param HeatmapLayer[] $heatmapLayers |
||
| 141 | */ |
||
| 142 | 16 | public function setHeatmapLayers(array $heatmapLayers) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * @param HeatmapLayer[] $heatmapLayers |
||
| 153 | */ |
||
| 154 | 16 | public function addHeatmapLayers(array $heatmapLayers) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * @return bool |
||
| 163 | */ |
||
| 164 | 40 | public function hasHeatmapLayer(HeatmapLayer $heatmapLayer) |
|
| 168 | |||
| 169 | 40 | public function addHeatmapLayer(HeatmapLayer $heatmapLayer) |
|
| 177 | |||
| 178 | 16 | public function removeHeatmapLayer(HeatmapLayer $heatmapLayer) |
|
| 184 | |||
| 185 | /** |
||
| 186 | * @return bool |
||
| 187 | */ |
||
| 188 | 36 | public function hasKmlLayers() |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @return KmlLayer[] |
||
| 195 | */ |
||
| 196 | 40 | public function getKmlLayers() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * @param KmlLayer[] $kmlLayers |
||
| 203 | */ |
||
| 204 | 16 | public function setKmlLayers(array $kmlLayers) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * @param KmlLayer[] $kmlLayers |
||
| 215 | */ |
||
| 216 | 16 | public function addKmlLayers(array $kmlLayers) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @return bool |
||
| 225 | */ |
||
| 226 | 36 | public function hasKmlLayer(KmlLayer $kmlLayer) |
|
| 230 | |||
| 231 | 36 | public function addKmlLayer(KmlLayer $kmlLayer) |
|
| 239 | |||
| 240 | 16 | public function removeKmlLayer(KmlLayer $kmlLayer) |
|
| 246 | |||
| 247 | 76 | private function addExtendable(ExtendableInterface $extendable) |
|
| 253 | |||
| 254 | 32 | private function removeExtendable(ExtendableInterface $extendable) |
|
| 260 | |||
| 261 | /** |
||
| 262 | * @return bool |
||
| 263 | */ |
||
| 264 | 76 | private function isAutoZoom() |
|
| 268 | } |
||
| 269 |