Complex classes like CreateUpdatePilotInformationCommand 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 CreateUpdatePilotInformationCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | final class CreateUpdatePilotInformationCommand |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var int |
||
14 | */ |
||
15 | private $pilotId; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $pilotLicenceNumber = ''; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $trainingPilotLicenceNumber = ''; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $lastTrainingFlightDate = ''; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $isPilotClassA = false; |
||
36 | |||
37 | /** |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $isPilotClassB = false; |
||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | private $isPilotClassC = false; |
||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | private $isPilotClassD = false; |
||
49 | /** |
||
50 | * @var bool |
||
51 | */ |
||
52 | private $isPilotGaz = false; |
||
53 | /** |
||
54 | * @var bool |
||
55 | */ |
||
56 | private $isMedicalOwner = false; |
||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | private $endMedicalDate = ''; |
||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | private $startMedicalDate = ''; |
||
65 | /** |
||
66 | * @var bool |
||
67 | */ |
||
68 | private $hasQualifStatic = false; |
||
69 | /** |
||
70 | * @var bool |
||
71 | */ |
||
72 | private $hasQualifNight = false; |
||
73 | /** |
||
74 | * @var bool |
||
75 | */ |
||
76 | private $hasQualifPro = false; |
||
77 | /** |
||
78 | * @var string |
||
79 | */ |
||
80 | private $lastOpcDate = ''; |
||
81 | /** |
||
82 | * @var string |
||
83 | */ |
||
84 | private $lastProRefreshDate = ''; |
||
85 | /** |
||
86 | * @var bool |
||
87 | */ |
||
88 | private $hasQualifInstructor = false; |
||
89 | /** |
||
90 | * @var string |
||
91 | */ |
||
92 | private $lastInstructorRefreshDate = ''; |
||
93 | /** |
||
94 | * @var bool |
||
95 | */ |
||
96 | private $hasQualifExaminator = false; |
||
97 | /** |
||
98 | * @var string |
||
99 | */ |
||
100 | private $lastExaminatorRefreshDate = ''; |
||
101 | /** |
||
102 | * @var bool |
||
103 | */ |
||
104 | private $hasRadio = false; |
||
105 | /** |
||
106 | * @var string |
||
107 | */ |
||
108 | private $radioLicenceNumber = ''; |
||
109 | /** |
||
110 | * @var string |
||
111 | */ |
||
112 | private $radioLicenceDate = ''; |
||
113 | /** |
||
114 | * @var bool |
||
115 | */ |
||
116 | private $hasTrainingFirstHelp = false; |
||
117 | /** |
||
118 | * @var string |
||
119 | */ |
||
120 | private $lastTrainingFirstHelpDate = ''; |
||
121 | /** |
||
122 | * @var string |
||
123 | */ |
||
124 | private $certificationNumberTrainingFirstHelp = ''; |
||
125 | /** |
||
126 | * @var bool |
||
127 | */ |
||
128 | private $hasTrainingFire = false; |
||
129 | /** |
||
130 | * @var string |
||
131 | */ |
||
132 | private $lastTrainingFireDate = ''; |
||
133 | /** |
||
134 | * @var string |
||
135 | */ |
||
136 | private $certificationNumberTrainingFire = ''; |
||
137 | |||
138 | public function __construct($pilotId) |
||
142 | |||
143 | /** |
||
144 | * @return mixed |
||
145 | */ |
||
146 | public function getPilotId() |
||
150 | |||
151 | /** |
||
152 | * @return string |
||
153 | */ |
||
154 | public function getPilotLicenceNumber(): string |
||
158 | |||
159 | /** |
||
160 | * @param string $pilotLicenceNumber |
||
161 | * @return CreateUpdatePilotInformationCommand |
||
162 | */ |
||
163 | public function setPilotLicenceNumber(string $pilotLicenceNumber): CreateUpdatePilotInformationCommand |
||
168 | |||
169 | /** |
||
170 | * @return string |
||
171 | */ |
||
172 | public function getTrainingPilotLicenceNumber(): string |
||
176 | |||
177 | /** |
||
178 | * @param string $trainingPilotLicenceNumber |
||
179 | * @return CreateUpdatePilotInformationCommand |
||
180 | */ |
||
181 | public function setTrainingPilotLicenceNumber(string $trainingPilotLicenceNumber |
||
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getLastTrainingFlightDate(): string |
||
194 | |||
195 | /** |
||
196 | * @param string $lastTrainingFlightDate |
||
197 | * @return CreateUpdatePilotInformationCommand |
||
198 | */ |
||
199 | public function setLastTrainingFlightDate(string $lastTrainingFlightDate): CreateUpdatePilotInformationCommand |
||
204 | |||
205 | /** |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function isPilotClassA(): bool |
||
212 | |||
213 | /** |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function getIsPilotClassA(): bool |
||
220 | |||
221 | /** |
||
222 | * @param bool $isPilotClassA |
||
223 | * @return CreateUpdatePilotInformationCommand |
||
224 | */ |
||
225 | public function setIsPilotClassA(bool $isPilotClassA): CreateUpdatePilotInformationCommand |
||
230 | |||
231 | /** |
||
232 | * @return bool |
||
233 | */ |
||
234 | public function isPilotClassB(): bool |
||
238 | |||
239 | /** |
||
240 | * @return bool |
||
241 | */ |
||
242 | public function getIsPilotClassB(): bool |
||
246 | |||
247 | /** |
||
248 | * @param bool $isPilotClassB |
||
249 | * @return CreateUpdatePilotInformationCommand |
||
250 | */ |
||
251 | public function setIsPilotClassB(bool $isPilotClassB): CreateUpdatePilotInformationCommand |
||
256 | |||
257 | /** |
||
258 | * @return bool |
||
259 | */ |
||
260 | public function isPilotClassC(): bool |
||
264 | |||
265 | /** |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function getIsPilotClassC(): bool |
||
272 | |||
273 | /** |
||
274 | * @param bool $isPilotClassC |
||
275 | * @return CreateUpdatePilotInformationCommand |
||
276 | */ |
||
277 | public function setIsPilotClassC(bool $isPilotClassC): CreateUpdatePilotInformationCommand |
||
282 | |||
283 | /** |
||
284 | * @return bool |
||
285 | */ |
||
286 | public function isPilotClassD(): bool |
||
290 | |||
291 | |||
292 | /** |
||
293 | * @return bool |
||
294 | */ |
||
295 | public function getIsPilotClassD(): bool |
||
299 | |||
300 | /** |
||
301 | * @param bool $isPilotClassD |
||
302 | * @return CreateUpdatePilotInformationCommand |
||
303 | */ |
||
304 | public function setIsPilotClassD(bool $isPilotClassD): CreateUpdatePilotInformationCommand |
||
309 | |||
310 | /** |
||
311 | * @return bool |
||
312 | */ |
||
313 | public function isPilotGaz(): bool |
||
317 | |||
318 | /** |
||
319 | * @return bool |
||
320 | */ |
||
321 | public function getIsPilotGaz(): bool |
||
325 | |||
326 | /** |
||
327 | * @param bool $isPilotGaz |
||
328 | * @return CreateUpdatePilotInformationCommand |
||
329 | */ |
||
330 | public function setIsPilotGaz(bool $isPilotGaz): CreateUpdatePilotInformationCommand |
||
335 | |||
336 | /** |
||
337 | * @return bool |
||
338 | */ |
||
339 | public function getIsMedicalOwner(): bool |
||
343 | |||
344 | /** |
||
345 | * @param bool $isMedicalOwner |
||
346 | * @return CreateUpdatePilotInformationCommand |
||
347 | */ |
||
348 | public function setIsMedicalOwner(bool $isMedicalOwner): CreateUpdatePilotInformationCommand |
||
353 | |||
354 | /** |
||
355 | * @return string |
||
356 | */ |
||
357 | public function getEndMedicalDate(): string |
||
361 | |||
362 | /** |
||
363 | * @param string $endMedicalDate |
||
364 | * @return CreateUpdatePilotInformationCommand |
||
365 | */ |
||
366 | public function setEndMedicalDate(string $endMedicalDate): CreateUpdatePilotInformationCommand |
||
371 | |||
372 | /** |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getStartMedicalDate(): string |
||
379 | |||
380 | /** |
||
381 | * @param string $startMedicalDate |
||
382 | * @return CreateUpdatePilotInformationCommand |
||
383 | */ |
||
384 | public function setStartMedicalDate(string $startMedicalDate): CreateUpdatePilotInformationCommand |
||
389 | |||
390 | /** |
||
391 | * @return bool |
||
392 | */ |
||
393 | public function getIsHasQualifStatic(): bool |
||
397 | |||
398 | /** |
||
399 | * @return bool |
||
400 | */ |
||
401 | public function getHasQualifStatic(): bool |
||
405 | |||
406 | /** |
||
407 | * @param bool $hasQualifStatic |
||
408 | * @return CreateUpdatePilotInformationCommand |
||
409 | */ |
||
410 | public function setHasQualifStatic(bool $hasQualifStatic): CreateUpdatePilotInformationCommand |
||
415 | |||
416 | /** |
||
417 | * @return bool |
||
418 | */ |
||
419 | public function getIsHasQualifNight(): bool |
||
423 | |||
424 | /** |
||
425 | * @return bool |
||
426 | */ |
||
427 | public function getHasQualifNight(): bool |
||
431 | |||
432 | /** |
||
433 | * @param bool $hasQualifNight |
||
434 | * @return CreateUpdatePilotInformationCommand |
||
435 | */ |
||
436 | public function setHasQualifNight(bool $hasQualifNight): CreateUpdatePilotInformationCommand |
||
441 | |||
442 | /** |
||
443 | * @return bool |
||
444 | */ |
||
445 | public function getIsHasQualifPro(): bool |
||
449 | |||
450 | /** |
||
451 | * @return bool |
||
452 | */ |
||
453 | public function getHasQualifPro(): bool |
||
457 | |||
458 | /** |
||
459 | * @param bool $hasQualifPro |
||
460 | * @return CreateUpdatePilotInformationCommand |
||
461 | */ |
||
462 | public function setHasQualifPro(bool $hasQualifPro): CreateUpdatePilotInformationCommand |
||
467 | |||
468 | /** |
||
469 | * @return string |
||
470 | */ |
||
471 | public function getLastOpcDate(): string |
||
475 | |||
476 | /** |
||
477 | * @param string $lastOpcDate |
||
478 | * @return CreateUpdatePilotInformationCommand |
||
479 | */ |
||
480 | public function setLastOpcDate(string $lastOpcDate): CreateUpdatePilotInformationCommand |
||
485 | |||
486 | /** |
||
487 | * @return string |
||
488 | */ |
||
489 | public function getLastProRefreshDate(): string |
||
493 | |||
494 | /** |
||
495 | * @param string $lastProRefreshDate |
||
496 | * @return CreateUpdatePilotInformationCommand |
||
497 | */ |
||
498 | public function setLastProRefreshDate(string $lastProRefreshDate): CreateUpdatePilotInformationCommand |
||
503 | |||
504 | /** |
||
505 | * @return bool |
||
506 | */ |
||
507 | public function getIsHasQualifInstructor(): bool |
||
511 | |||
512 | /** |
||
513 | * @return bool |
||
514 | */ |
||
515 | public function getHasQualifInstructor(): bool |
||
519 | |||
520 | /** |
||
521 | * @param bool $hasQualifInstructor |
||
522 | * @return CreateUpdatePilotInformationCommand |
||
523 | */ |
||
524 | public function setHasQualifInstructor(bool $hasQualifInstructor): CreateUpdatePilotInformationCommand |
||
529 | |||
530 | /** |
||
531 | * @return string |
||
532 | */ |
||
533 | public function getLastInstructorRefreshDate(): string |
||
537 | |||
538 | /** |
||
539 | * @param string $lastInstructorRefreshDate |
||
540 | * @return CreateUpdatePilotInformationCommand |
||
541 | */ |
||
542 | public function setLastInstructorRefreshDate(string $lastInstructorRefreshDate): CreateUpdatePilotInformationCommand |
||
547 | |||
548 | /** |
||
549 | * @return bool |
||
550 | */ |
||
551 | public function getIsHasQualifExaminator(): bool |
||
555 | |||
556 | /** |
||
557 | * @return bool |
||
558 | */ |
||
559 | public function getHasQualifExaminator(): bool |
||
563 | |||
564 | /** |
||
565 | * @param bool $hasQualifExaminator |
||
566 | * @return CreateUpdatePilotInformationCommand |
||
567 | */ |
||
568 | public function setHasQualifExaminator(bool $hasQualifExaminator): CreateUpdatePilotInformationCommand |
||
573 | |||
574 | /** |
||
575 | * @return string |
||
576 | */ |
||
577 | public function getLastExaminatorRefreshDate(): string |
||
581 | |||
582 | /** |
||
583 | * @param string $lastExaminatorRefreshDate |
||
584 | * @return CreateUpdatePilotInformationCommand |
||
585 | */ |
||
586 | public function setLastExaminatorRefreshDate(string $lastExaminatorRefreshDate): CreateUpdatePilotInformationCommand |
||
591 | |||
592 | /** |
||
593 | * @return bool |
||
594 | */ |
||
595 | public function getIsHasRadio(): bool |
||
599 | |||
600 | /** |
||
601 | * @return bool |
||
602 | */ |
||
603 | public function getHasRadio(): bool |
||
607 | |||
608 | /** |
||
609 | * @param bool $hasRadio |
||
610 | * @return CreateUpdatePilotInformationCommand |
||
611 | */ |
||
612 | public function setHasRadio(bool $hasRadio): CreateUpdatePilotInformationCommand |
||
617 | |||
618 | /** |
||
619 | * @return string |
||
620 | */ |
||
621 | public function getRadioLicenceNumber(): string |
||
625 | |||
626 | /** |
||
627 | * @param string $radioLicenceNumber |
||
628 | * @return CreateUpdatePilotInformationCommand |
||
629 | */ |
||
630 | public function setRadioLicenceNumber(string $radioLicenceNumber): CreateUpdatePilotInformationCommand |
||
635 | |||
636 | /** |
||
637 | * @return string |
||
638 | */ |
||
639 | public function getRadioLicenceDate(): string |
||
643 | |||
644 | /** |
||
645 | * @param string $radioLicenceDate |
||
646 | * @return CreateUpdatePilotInformationCommand |
||
647 | */ |
||
648 | public function setRadioLicenceDate(string $radioLicenceDate): CreateUpdatePilotInformationCommand |
||
653 | |||
654 | /** |
||
655 | * @return bool |
||
656 | */ |
||
657 | public function getIsHasTrainingFirstHelp(): bool |
||
661 | |||
662 | /** |
||
663 | * @return bool |
||
664 | */ |
||
665 | public function getHasTrainingFirstHelp(): bool |
||
669 | |||
670 | /** |
||
671 | * @param bool $hasTrainingFirstHelp |
||
672 | * @return CreateUpdatePilotInformationCommand |
||
673 | */ |
||
674 | public function setHasTrainingFirstHelp(bool $hasTrainingFirstHelp): CreateUpdatePilotInformationCommand |
||
679 | |||
680 | /** |
||
681 | * @return string |
||
682 | */ |
||
683 | public function getLastTrainingFirstHelpDate(): string |
||
687 | |||
688 | /** |
||
689 | * @param string $lastTrainingFirstHelpDate |
||
690 | * @return CreateUpdatePilotInformationCommand |
||
691 | */ |
||
692 | public function setLastTrainingFirstHelpDate(string $lastTrainingFirstHelpDate): CreateUpdatePilotInformationCommand |
||
697 | |||
698 | /** |
||
699 | * @return string |
||
700 | */ |
||
701 | public function getCertificationNumberTrainingFirstHelp(): string |
||
705 | |||
706 | /** |
||
707 | * @param string $certificationNumberTrainingFirstHelp |
||
708 | * @return CreateUpdatePilotInformationCommand |
||
709 | */ |
||
710 | public function setCertificationNumberTrainingFirstHelp(string $certificationNumberTrainingFirstHelp |
||
715 | |||
716 | /** |
||
717 | * @return bool |
||
718 | */ |
||
719 | public function getIsHasTrainingFire(): bool |
||
723 | |||
724 | /** |
||
725 | * @return bool |
||
726 | */ |
||
727 | public function getHasTrainingFire(): bool |
||
731 | |||
732 | /** |
||
733 | * @param bool $hasTrainingFire |
||
734 | * @return CreateUpdatePilotInformationCommand |
||
735 | */ |
||
736 | public function setHasTrainingFire(bool $hasTrainingFire): CreateUpdatePilotInformationCommand |
||
741 | |||
742 | /** |
||
743 | * @return string |
||
744 | */ |
||
745 | public function getLastTrainingFireDate(): string |
||
749 | |||
750 | /** |
||
751 | * @param string $lastTrainingFireDate |
||
752 | * @return CreateUpdatePilotInformationCommand |
||
753 | */ |
||
754 | public function setLastTrainingFireDate(string $lastTrainingFireDate): CreateUpdatePilotInformationCommand |
||
759 | |||
760 | /** |
||
761 | * @return string |
||
762 | */ |
||
763 | public function getCertificationNumberTrainingFire(): string |
||
767 | |||
768 | /** |
||
769 | * @param string $certificationNumberTrainingFire |
||
770 | * @return CreateUpdatePilotInformationCommand |
||
771 | */ |
||
772 | public function setCertificationNumberTrainingFire(string $certificationNumberTrainingFire |
||
777 | |||
778 | public function fromPilot(Pilot $pilot) |
||
870 | |||
871 | |||
872 | } |