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