Complex classes like Pompier 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 Pompier, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class Pompier |
||
13 | { |
||
14 | /** |
||
15 | * Type. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $type = 'pompier'; |
||
20 | |||
21 | /** |
||
22 | * Inscription dans les plannings du pompier. |
||
23 | * |
||
24 | * @var SDIS62\Core\Ops\Entity\PlageHoraire[] |
||
25 | */ |
||
26 | protected $plages_horaires; |
||
27 | |||
28 | /** |
||
29 | * Centre dans lequel le pompier est affecté. |
||
30 | * |
||
31 | * @var SDIS62\Core\Ops\Entity\Centre |
||
32 | */ |
||
33 | protected $centre; |
||
34 | |||
35 | /** |
||
36 | * Matricule du pompier. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $matricule; |
||
41 | |||
42 | /** |
||
43 | * Engagement du pompier. |
||
44 | * |
||
45 | * @var SDIS62\Core\Ops\Entity\Engagement\PompierEngagement[] |
||
46 | */ |
||
47 | protected $engagements; |
||
48 | |||
49 | /** |
||
50 | * Grade. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $grade; |
||
55 | |||
56 | /** |
||
57 | * Nom du pompier. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $name; |
||
62 | |||
63 | /** |
||
64 | * Numéro de téléphone. |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $phone_number; |
||
69 | |||
70 | /** |
||
71 | * Etat du pompier. |
||
72 | * |
||
73 | * @var SDIS62\Core\Ops\Entity\Statut |
||
74 | */ |
||
75 | protected $statut; |
||
76 | |||
77 | /** |
||
78 | * Profesionnel ? |
||
79 | * |
||
80 | * @var bool |
||
81 | */ |
||
82 | protected $is_pro; |
||
83 | |||
84 | /** |
||
85 | * Coordonnées du pompier. |
||
86 | * |
||
87 | * @var SDIS62\Core\Ops\Entity\Coordinates |
||
88 | */ |
||
89 | protected $coordinates; |
||
90 | |||
91 | /** |
||
92 | * Ajout d'un pompier. |
||
93 | * |
||
94 | * @param string $name |
||
95 | * @param string $matricule |
||
96 | * @param SDIS62\Core\Ops\Entity\Centre $centre |
||
97 | */ |
||
98 | public function __construct($name, $matricule, Centre $centre) |
||
108 | |||
109 | /** |
||
110 | * Get the value of Plannings du pompier. |
||
111 | * |
||
112 | * @return SDIS62\Core\Ops\Entity\Planning[] |
||
113 | */ |
||
114 | public function getPlannings() |
||
126 | |||
127 | /** |
||
128 | * Get the value of Plages horaires. |
||
129 | * |
||
130 | * @return SDIS62\Core\Ops\Entity\PlageHoraire[] |
||
131 | */ |
||
132 | public function getPlagesHoraires() |
||
136 | |||
137 | /** |
||
138 | * Get the value of Gardes. |
||
139 | * |
||
140 | * @return SDIS62\Core\Ops\Entity\PlageHoraire\Garde[] |
||
141 | */ |
||
142 | public function getGardes() |
||
154 | |||
155 | /** |
||
156 | * Get the value of Dispos. |
||
157 | * |
||
158 | * @return SDIS62\Core\Ops\Entity\PlageHoraire\Dispo[] |
||
159 | */ |
||
160 | public function getDispos() |
||
172 | |||
173 | /** |
||
174 | * Ajout d'une plage horaire. |
||
175 | * |
||
176 | * @param SDIS62\Core\Ops\Entity\PlageHoraire $plage_horaire |
||
177 | * |
||
178 | * @return self |
||
179 | */ |
||
180 | public function addPlageHoraire(PlageHoraire $plage_horaire) |
||
186 | |||
187 | /** |
||
188 | * Get the value of Centre dans lequel le pompier est affecté. |
||
189 | * |
||
190 | * @return SDIS62\Core\Ops\Entity\Centre |
||
191 | */ |
||
192 | public function getCentre() |
||
196 | |||
197 | /** |
||
198 | * Set the value of Centre dans lequel le pompier est affecté. |
||
199 | * |
||
200 | * @param SDIS62\Core\Ops\Entity\Centre centre |
||
201 | * |
||
202 | * @return self |
||
203 | */ |
||
204 | public function setCentre(Centre $centre) |
||
216 | |||
217 | /** |
||
218 | * Get the value of Matricule du pompier. |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | public function getMatricule() |
||
226 | |||
227 | /** |
||
228 | * Get the value of Nom du pompier. |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | public function getName() |
||
236 | |||
237 | /** |
||
238 | * Set the value of Nom du pompier. |
||
239 | * |
||
240 | * @param string name |
||
241 | * |
||
242 | * @return self |
||
243 | */ |
||
244 | public function setName($name) |
||
250 | |||
251 | /** |
||
252 | * Get the value of Grade du pompier. |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | public function getGrade() |
||
260 | |||
261 | /** |
||
262 | * Set the value of Grade du pompier. |
||
263 | * |
||
264 | * @param string grade |
||
265 | * |
||
266 | * @return self |
||
267 | */ |
||
268 | public function setGrade($grade) |
||
274 | |||
275 | /** |
||
276 | * Get the value of Liste des engagements du pompier. |
||
277 | * |
||
278 | * @return SDIS62\Core\Ops\Entity\Engagement\PompierEngagement[] |
||
279 | */ |
||
280 | public function getEngagements() |
||
284 | |||
285 | /** |
||
286 | * Ajoute un engagement au pompier. |
||
287 | * |
||
288 | * @param SDIS62\Core\Ops\Entity\Engagement\PompierEngagement $engagement |
||
289 | * |
||
290 | * @return self |
||
291 | */ |
||
292 | public function addEngagement(PompierEngagement $engagement) |
||
298 | |||
299 | /** |
||
300 | * Le matériel est il actuellement engagé ? |
||
301 | * |
||
302 | * @return bool |
||
303 | */ |
||
304 | public function isEngage() |
||
314 | |||
315 | /** |
||
316 | * Retourne vrai si le pompier est en garde. |
||
317 | * |
||
318 | * @return bool |
||
319 | */ |
||
320 | public function isEnGarde() |
||
336 | |||
337 | /** |
||
338 | * Get the value of Type de pompier. |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | final public function getType() |
||
346 | |||
347 | /** |
||
348 | * Get the value of Numéro de téléphone. |
||
349 | * |
||
350 | * @return string |
||
351 | */ |
||
352 | public function getPhoneNumber() |
||
356 | |||
357 | /** |
||
358 | * Set the value of Numéro de téléphone. |
||
359 | * |
||
360 | * @param string|null $phone_number |
||
361 | * |
||
362 | * @throws InvalidPhoneNumberException |
||
363 | * |
||
364 | * @return self |
||
365 | */ |
||
366 | public function setPhoneNumber($phone_number) |
||
377 | |||
378 | /** |
||
379 | * Get the value of Etat du pompier. |
||
380 | * |
||
381 | * @return SDIS62\Core\Ops\Entity\Statut |
||
382 | */ |
||
383 | public function getStatut() |
||
387 | |||
388 | /** |
||
389 | * Set the value of Etat du pompier. |
||
390 | * |
||
391 | * @param SDIS62\Core\Ops\Entity\Statut statut |
||
392 | * |
||
393 | * @return self |
||
394 | */ |
||
395 | public function setStatut(Statut $statut) |
||
401 | |||
402 | /** |
||
403 | * Get the value of Pro ou volontaire ? |
||
404 | * |
||
405 | * @return bool |
||
406 | */ |
||
407 | public function isPro() |
||
411 | |||
412 | /** |
||
413 | * Set the value of Pro ou volontaire ? |
||
414 | * |
||
415 | * @param bool is_pro |
||
416 | * |
||
417 | * @return self |
||
418 | */ |
||
419 | public function setPro($value = true) |
||
425 | |||
426 | /** |
||
427 | * Get the value of Coordonnées du pompier. |
||
428 | * |
||
429 | * @return SDIS62\Core\Ops\Entity\Coordinates |
||
430 | */ |
||
431 | public function getCoordinates() |
||
435 | |||
436 | /** |
||
437 | * Set the value of Coordonnées du pompier. |
||
438 | * |
||
439 | * @param SDIS62\Core\Ops\Entity\Coordinates $coordinates |
||
440 | * |
||
441 | * @return self |
||
442 | */ |
||
443 | public function setCoordinates(Coordinates $coordinates) |
||
453 | } |
||
454 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..