Complex classes like Markers 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 Markers, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Markers extends \Nette\Object |
||
17 | { |
||
18 | |||
19 | const DROP = 'DROP', BOUNCE = 'BOUNCE'; |
||
20 | |||
21 | /** @var array */ |
||
22 | private $markers = array(); |
||
23 | |||
24 | /** @var String */ |
||
25 | private $iconDefaultPath; |
||
26 | |||
27 | /** @var Boolean */ |
||
28 | private $bound = FALSE; |
||
29 | |||
30 | /** @var Boolean */ |
||
31 | private $markerClusterer = FALSE; |
||
32 | |||
33 | private $clusterOptions = array(); |
||
34 | |||
35 | |||
36 | /** |
||
37 | * @internal |
||
38 | * @param array $markers |
||
39 | * @throws \Nette\InvalidArgumentException |
||
40 | */ |
||
41 | public function addMarkers(array $markers) |
||
51 | |||
52 | |||
53 | /** |
||
54 | * @param array $position |
||
55 | * @param boolean $animation |
||
56 | * @param String $title |
||
57 | * @return Markers |
||
58 | */ |
||
59 | public function addMarker(array $position, $animation = false, $title = null) |
||
78 | |||
79 | |||
80 | public function getMarker() |
||
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | public function getMarkers() |
||
92 | |||
93 | |||
94 | public function deleteMarkers() |
||
98 | |||
99 | |||
100 | /** |
||
101 | * @param String $message |
||
102 | * @param Boolean $autoOpen |
||
103 | * @return Markers |
||
104 | */ |
||
105 | public function setMessage($message, $autoOpen = false) |
||
117 | |||
118 | |||
119 | /** |
||
120 | * |
||
121 | * @param Boolean $cluster |
||
122 | * @return \Oli\GoogleAPI\Markers |
||
123 | * @throws \InvalidArgumentException |
||
124 | */ |
||
125 | public function isMarkerClusterer($cluster = true) |
||
135 | |||
136 | |||
137 | /** |
||
138 | * |
||
139 | * @return Boolean |
||
140 | */ |
||
141 | public function getMarkerClusterer() |
||
145 | |||
146 | |||
147 | /** |
||
148 | * @param array $options |
||
149 | * @return \Oli\GoogleAPI\Markers |
||
150 | */ |
||
151 | public function setClusterOptions($options = array()) |
||
156 | |||
157 | |||
158 | /** |
||
159 | * @return array |
||
160 | */ |
||
161 | public function getClusterOptions() |
||
165 | |||
166 | /** |
||
167 | * @param Boolean $bound Show all of markers |
||
168 | * @return \Oli\GoogleAPI\MapAPI |
||
169 | */ |
||
170 | public function fitBounds($bound = true) |
||
180 | |||
181 | |||
182 | /** |
||
183 | * |
||
184 | * @return Boolean |
||
185 | */ |
||
186 | public function getBound() |
||
190 | |||
191 | |||
192 | /** |
||
193 | * |
||
194 | * @param Marker\Icon | String $icon |
||
195 | */ |
||
196 | public function setIcon($icon) |
||
212 | |||
213 | |||
214 | /** |
||
215 | * |
||
216 | * @param String $defaultPath |
||
217 | * @return \Oli\GoogleAPI\Markers |
||
218 | */ |
||
219 | public function setDefaultIconPath($defaultPath) |
||
230 | |||
231 | |||
232 | public function getDefaultIconPath() |
||
236 | |||
237 | |||
238 | /** |
||
239 | * |
||
240 | * @param String $color Color can be 24-bit color or: green, purple, yellow, blue, gray, orange, red |
||
241 | * @return \Oli\GoogleAPI\Markers |
||
242 | */ |
||
243 | public function setColor($color) |
||
258 | |||
259 | |||
260 | private function createMarker(array $marker) |
||
316 | } |
||
317 |