Conditions | 15 |
Paths | 16384 |
Total Lines | 97 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
38 | public function __invoke(CreateUpdatePilotInformationCommand $command) |
||
39 | { |
||
40 | $pilotId = PilotId::create($command->getPilotId()); |
||
41 | $pilot = $this->getOrCreatePilot($pilotId); |
||
42 | |||
43 | |||
44 | if ($command->getIsMedicalOwner()) { |
||
45 | $pilot->medical(); |
||
46 | } else { |
||
47 | $pilot->removeMedical(); |
||
48 | } |
||
49 | |||
50 | if ($command->getIsPilotClassA()) { |
||
51 | $pilot->hasClassA(); |
||
52 | } else { |
||
53 | $pilot->removeClassA(); |
||
54 | } |
||
55 | if ($command->getIsPilotClassB()) { |
||
56 | $pilot->hasClassB(); |
||
57 | } else { |
||
58 | $pilot->removeClassB(); |
||
59 | } |
||
60 | if ($command->getIsPilotClassC()) { |
||
61 | $pilot->hasClassC(); |
||
62 | } else { |
||
63 | $pilot->removeClassC(); |
||
64 | } |
||
65 | if ($command->getIsPilotClassD()) { |
||
66 | $pilot->hasClassD(); |
||
67 | } else { |
||
68 | $pilot->removeClassD(); |
||
69 | } |
||
70 | if ($command->getIsPilotGaz()) { |
||
71 | $pilot->gazPilot(); |
||
72 | } else { |
||
73 | $pilot->removeGazPilot(); |
||
74 | } |
||
75 | if ($command->getIsHasQualifStatic()) { |
||
76 | $pilot->staticQualif(); |
||
77 | } else { |
||
78 | $pilot->removeStaticQualif(); |
||
79 | } |
||
80 | if ($command->getIsHasQualifNight()) { |
||
81 | $pilot->nightQualif(); |
||
82 | } else { |
||
83 | $pilot->removeNightQualif(); |
||
84 | } |
||
85 | if ($command->getIsHasQualifPro()) { |
||
86 | $pilot->proQualif(); |
||
87 | } else { |
||
88 | $pilot->removeProQualif(); |
||
89 | } |
||
90 | if ($command->getIsHasQualifInstructor()) { |
||
91 | $pilot->instructorQualif(); |
||
92 | } else { |
||
93 | $pilot->removeInstructorQualif(); |
||
94 | } |
||
95 | if ($command->getIsHasQualifExaminator()) { |
||
96 | $pilot->examinatorQualif(); |
||
97 | } else { |
||
98 | $pilot->removeExaminatorQualif(); |
||
99 | } |
||
100 | if ($command->getIsHasRadio()) { |
||
101 | $pilot->radio(); |
||
102 | } else { |
||
103 | $pilot->removeRadio(); |
||
104 | } |
||
105 | if ($command->getIsHasTrainingFirstHelp()) { |
||
106 | $pilot->trainingFirstHelp(); |
||
107 | } else { |
||
108 | $pilot->removeTrainingFirstHelp(); |
||
109 | } |
||
110 | if ($command->getIsHasTrainingFire()) { |
||
111 | $pilot->trainingFire(); |
||
112 | } else { |
||
113 | $pilot->removeTrainingFire(); |
||
114 | } |
||
115 | |||
116 | $pilot->attributePilotLicenceNumber(PilotLicenceNumber::create($command->getPilotLicenceNumber())); |
||
117 | $pilot->attributeTrainingPilotLicenceNumber(PilotTrainingLicenceNumber::create($command->getTrainingPilotLicenceNumber())); |
||
118 | $pilot->attributeRadioLicenceNumber(RadioLicenceNumber::create($command->getRadioLicenceNumber())); |
||
119 | $pilot->attributeCertificationNumberTrainingFirstHelp(FirstHelpCertificationNumber::create($command->getCertificationNumberTrainingFirstHelp())); |
||
120 | $pilot->attributeCertificationNumberTrainingFire(FireCertificationNumber::create($command->getCertificationNumberTrainingFire())); |
||
121 | |||
122 | $pilot->attributeLastTrainingFlightDate(LastTrainingDate::fromString($command->getLastTrainingFlightDate())); |
||
123 | $pilot->attributeEndMedicalDate(EndDate::fromString($command->getEndMedicalDate())); |
||
124 | $pilot->attributeStartMedicalDate(StartDate::fromString($command->getStartMedicalDate())); |
||
125 | $pilot->attributeLastOpcDate(LastTrainingDate::fromString($command->getLastOpcDate())); |
||
126 | $pilot->attributeLastProRefreshDate(LastTrainingDate::fromString($command->getLastProRefreshDate())); |
||
127 | $pilot->attributeLastInstructorRefreshDate(LastTrainingDate::fromString($command->getLastInstructorRefreshDate())); |
||
128 | $pilot->attributeLastExaminatorRefreshDate(LastTrainingDate::fromString($command->getLastExaminatorRefreshDate())); |
||
129 | $pilot->attributeLastTrainingFireDate(LastTrainingDate::fromString($command->getLastTrainingFireDate())); |
||
130 | $pilot->attributeRadioLicenceDate(RadioLicenceDate::fromString($command->getRadioLicenceDate())); |
||
131 | $pilot->attributeLastTrainingFirstHelpDate(LastTrainingDate::fromString($command->getLastTrainingFirstHelpDate())); |
||
132 | |||
133 | $this->pilotRepository->save($pilot); |
||
134 | } |
||
135 | |||
153 | } |