Conditions | 13 |
Paths | 50 |
Total Lines | 89 |
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 |
||
152 | public function getFirstInvalidStep(Step $step) |
||
153 | { |
||
154 | $firstStep = $this->service->getFirstStepDefinition(); |
||
155 | if ($step === $firstStep->getStep()) { |
||
156 | /* |
||
157 | * The first step is always valid. |
||
158 | */ |
||
159 | return null; |
||
160 | } |
||
161 | |||
162 | /* |
||
163 | * If there is no form instance, and the request is not in the first |
||
164 | * step, obviously the user should not be there. |
||
165 | */ |
||
166 | if (false === $this->formObject->hasForm()) { |
||
167 | return $firstStep; |
||
168 | } |
||
169 | |||
170 | /** @var StepDefinition[] $stepDefinitionsToTest */ |
||
171 | $stepDefinitionsToTest = []; |
||
172 | $invalidStepDefinition = null; |
||
173 | $currentStepDefinition = $stepDefinition = $this->service->getStepDefinition($step); |
||
174 | |||
175 | while ($stepDefinition->hasPreviousDefinition()) { |
||
176 | $stepDefinition = $stepDefinition->getPreviousDefinition(); |
||
177 | |||
178 | if ($stepDefinition->hasActivation()) { |
||
179 | if (true === $this->service->getStepDefinitionConditionResult($stepDefinition)) { |
||
180 | array_unshift($stepDefinitionsToTest, $stepDefinition); |
||
181 | } |
||
182 | } else { |
||
183 | array_unshift($stepDefinitionsToTest, $stepDefinition); |
||
184 | } |
||
185 | } |
||
186 | |||
187 | foreach ($stepDefinitionsToTest as $stepDefinition) { |
||
188 | |||
189 | $step = $stepDefinition->getStep(); |
||
190 | |||
191 | /* |
||
192 | * If the form was already validated, no need to do it again. |
||
193 | */ |
||
194 | if ($this->persistence->stepWasValidated($step)) { |
||
195 | continue; |
||
196 | } |
||
197 | |||
198 | $result = $this->validateStep($step); |
||
199 | |||
200 | if ($result->hasErrors()) { |
||
201 | $invalidStepDefinition = $stepDefinition; |
||
202 | |||
203 | $this->signalSlotDispatcher->dispatch( |
||
204 | self::class, |
||
205 | self::STEP_HAS_ERROR, |
||
206 | [ |
||
207 | $this->formObject, |
||
208 | $currentStepDefinition, |
||
209 | $invalidStepDefinition, |
||
210 | $result, |
||
211 | ] |
||
212 | ); |
||
213 | |||
214 | break; |
||
215 | } |
||
216 | } |
||
217 | |||
218 | if (null === $invalidStepDefinition |
||
219 | && $currentStepDefinition->hasActivation() |
||
220 | && false === $this->service->getStepDefinitionConditionResult($currentStepDefinition) |
||
221 | ) { |
||
222 | $invalidStepDefinition = end($stepDefinitionsToTest); |
||
223 | |||
224 | if (false === $invalidStepDefinition) { |
||
225 | return null; |
||
226 | } |
||
227 | |||
228 | $this->signalSlotDispatcher->dispatch( |
||
229 | self::class, |
||
230 | self::STEP_INVALID_ACTIVATION, |
||
231 | [ |
||
232 | $this->formObject, |
||
233 | $currentStepDefinition, |
||
234 | $invalidStepDefinition, |
||
235 | ] |
||
236 | ); |
||
237 | } |
||
238 | |||
239 | return $invalidStepDefinition; |
||
240 | } |
||
241 | |||
275 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.