Total Complexity | 92 |
Total Lines | 461 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 1 | Features | 0 |
Complex classes like Poi 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.
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 Poi, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class Poi |
||
19 | { |
||
20 | /** @var string */ |
||
21 | private $id; |
||
22 | |||
23 | /** @var string */ |
||
24 | private $type; |
||
25 | |||
26 | /** @var string */ |
||
27 | private $office; |
||
28 | |||
29 | /** @var string */ |
||
30 | private $street; |
||
31 | |||
32 | /** @var string */ |
||
33 | private $nr; |
||
34 | |||
35 | /** @var string */ |
||
36 | private $zip; |
||
37 | |||
38 | /** @var string */ |
||
39 | private $city; |
||
40 | |||
41 | /** @var int */ |
||
42 | private $x; |
||
43 | |||
44 | /** @var int */ |
||
45 | private $y; |
||
46 | |||
47 | /** @var float */ |
||
48 | private $latitude; |
||
49 | |||
50 | /** @var float */ |
||
51 | private $longitude; |
||
52 | |||
53 | /** @var array */ |
||
54 | private $services; |
||
55 | |||
56 | /** @var array */ |
||
57 | private $hours; |
||
58 | |||
59 | /** @var array */ |
||
60 | private $closedFrom; |
||
61 | |||
62 | /** @var array */ |
||
63 | private $closedTo; |
||
64 | |||
65 | /** @var string */ |
||
66 | private $note; |
||
67 | |||
68 | /** @var string */ |
||
69 | private $page; |
||
70 | |||
71 | /** |
||
72 | * @param string $city |
||
73 | */ |
||
74 | public function setCity($city) |
||
75 | { |
||
76 | $this->city = (string) $city; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | public function getCity() |
||
83 | { |
||
84 | return $this->city; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param array $closedFrom |
||
89 | */ |
||
90 | public function setClosedFrom(array $closedFrom) |
||
91 | { |
||
92 | $this->closedFrom = $closedFrom; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return array |
||
97 | */ |
||
98 | public function getClosedFrom() |
||
99 | { |
||
100 | return $this->closedFrom; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @param array $closedTo |
||
105 | */ |
||
106 | public function setClosedTo(array $closedTo) |
||
107 | { |
||
108 | $this->closedTo = $closedTo; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return array |
||
113 | */ |
||
114 | public function getClosedTo() |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param int $index |
||
121 | * @param Day $day |
||
122 | */ |
||
123 | public function addHour($index, Day $day) |
||
124 | { |
||
125 | $this->hours[(int) $index] = $day; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @param Day[] $hours |
||
130 | */ |
||
131 | public function setHours(array $hours) |
||
132 | { |
||
133 | $this->hours = $hours; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @return Day[] |
||
138 | */ |
||
139 | public function getHours() |
||
140 | { |
||
141 | return $this->hours; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param string $id |
||
146 | */ |
||
147 | public function setId($id) |
||
148 | { |
||
149 | $this->id = (string) $id; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getId() |
||
156 | { |
||
157 | return $this->id; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @param float $latitude |
||
162 | */ |
||
163 | public function setLatitude($latitude) |
||
164 | { |
||
165 | $this->latitude = (float) $latitude; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return float |
||
170 | */ |
||
171 | public function getLatitude() |
||
172 | { |
||
173 | return $this->latitude; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @param float $longitude |
||
178 | */ |
||
179 | public function setLongitude($longitude) |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @return float |
||
186 | */ |
||
187 | public function getLongitude() |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @param string $note |
||
194 | */ |
||
195 | public function setNote($note) |
||
196 | { |
||
197 | $this->note = (string) $note; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @return string |
||
202 | */ |
||
203 | public function getNote() |
||
204 | { |
||
205 | return $this->note; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @param string $nr |
||
210 | */ |
||
211 | public function setNr($nr) |
||
212 | { |
||
213 | $this->nr = (string) $nr; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * @return string |
||
218 | */ |
||
219 | public function getNr() |
||
220 | { |
||
221 | return $this->nr; |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * @param string $office |
||
226 | */ |
||
227 | public function setOffice($office) |
||
228 | { |
||
229 | $this->office = (string) $office; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getOffice() |
||
236 | { |
||
237 | return $this->office; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * @param Service $service |
||
242 | */ |
||
243 | public function addService(Service $service) |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @param Service[] $services |
||
250 | */ |
||
251 | public function setServices(array $services) |
||
252 | { |
||
253 | $this->services = $services; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * @return Service[] |
||
258 | */ |
||
259 | public function getServices() |
||
260 | { |
||
261 | return $this->services; |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * @param string $street |
||
266 | */ |
||
267 | public function setStreet($street) |
||
268 | { |
||
269 | $this->street = (string) $street; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * @return string |
||
274 | */ |
||
275 | public function getStreet() |
||
276 | { |
||
277 | return $this->street; |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * @param string $type |
||
282 | */ |
||
283 | public function setType($type) |
||
284 | { |
||
285 | $this->type = (string) $type; |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @return string |
||
290 | */ |
||
291 | public function getType() |
||
292 | { |
||
293 | return $this->type; |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * @param int $x |
||
298 | */ |
||
299 | public function setX($x) |
||
300 | { |
||
301 | $this->x = (int) $x; |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * @return int |
||
306 | */ |
||
307 | public function getX() |
||
308 | { |
||
309 | return $this->x; |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @param int $y |
||
314 | */ |
||
315 | public function setY($y) |
||
316 | { |
||
317 | $this->y = (int) $y; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @return int |
||
322 | */ |
||
323 | public function getY() |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @param string $zip |
||
330 | */ |
||
331 | public function setZip($zip) |
||
332 | { |
||
333 | $this->zip = (string) $zip; |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * @return string |
||
338 | */ |
||
339 | public function getZip() |
||
340 | { |
||
341 | return $this->zip; |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @return string |
||
346 | */ |
||
347 | public function getPage() |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @param string $page |
||
354 | */ |
||
355 | public function setPage($page) |
||
356 | { |
||
357 | $this->page = (string) $page; |
||
358 | } |
||
359 | |||
360 | /** |
||
361 | * Create a POI based on an XML-object |
||
362 | * |
||
363 | * @param SimpleXMLElement $xml |
||
364 | * |
||
365 | * @return Poi |
||
366 | * |
||
367 | * @throws BpostInvalidXmlResponseException |
||
368 | */ |
||
369 | public static function createFromXML(SimpleXMLElement $xml) |
||
479 | } |
||
480 | } |
||
481 |