| Conditions | 7 |
| Paths | 7 |
| Total Lines | 54 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 35 | public function handleAuthenticationProcess( |
||
| 36 | ?ServerRequestInterface $httpRequest, |
||
| 37 | IAuthenticationProcess $process, |
||
| 38 | IAuthenticationCallback $callback |
||
| 39 | ): IAuthentifierResponse { |
||
| 40 | if ($process->isOngoing()) { |
||
| 41 | $challenge = $this |
||
| 42 | ->container |
||
| 43 | ->get($process->getCurrentChallenge()) |
||
| 44 | ; |
||
| 45 | $challengeResponse = $challenge->process($process, $httpRequest); |
||
| 46 | |||
| 47 | $psrHttpResponse = $challengeResponse->getHttpResponse(); |
||
| 48 | |||
| 49 | if ($challengeResponse->isFinished()) { |
||
| 50 | return new AuthentifierResponse( |
||
| 51 | $challengeResponse |
||
| 52 | ->getAuthenticationProcess() |
||
| 53 | ->resetNFailedAttempts() |
||
| 54 | ->setToNextChallenge(), |
||
| 55 | null |
||
| 56 | ); |
||
| 57 | } elseif ($challengeResponse->isFailedAttempt()) { |
||
| 58 | $updatedProcess = $challengeResponse |
||
| 59 | ->getAuthenticationProcess() |
||
| 60 | ->incrementNFailedAttempts() |
||
| 61 | ; |
||
| 62 | if ($updatedProcess->isFailed()) { |
||
| 63 | return new AuthentifierResponse( |
||
| 64 | $updatedProcess, |
||
| 65 | null |
||
| 66 | ); |
||
| 67 | } else { |
||
| 68 | return new AuthentifierResponse( |
||
| 69 | $updatedProcess, |
||
| 70 | $psrHttpResponse |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | return new AuthentifierResponse( |
||
| 75 | $challengeResponse |
||
| 76 | ->getAuthenticationProcess(), |
||
| 77 | $psrHttpResponse |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | } elseif ($process->isFailed()) { |
||
| 81 | return new AuthentifierResponse( |
||
| 82 | $process, |
||
| 83 | $callback->handleFailedProcess($process) |
||
| 84 | ); |
||
| 85 | } elseif ($process->isSucceeded()) { |
||
| 86 | return new AuthentifierResponse( |
||
| 87 | $process, |
||
| 88 | $callback->handleSuccessfulProcess($process) |
||
| 89 | ); |
||
| 93 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: