| Conditions | 10 |
| Paths | 11 |
| Total Lines | 33 |
| Code Lines | 18 |
| 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 |
||
| 17 | public function handle($request, Closure $next) |
||
| 18 | { |
||
| 19 | $authenticator = app(Authenticator::class)->boot($request); |
||
| 20 | $user = $request->user(); |
||
| 21 | |||
| 22 | if ($user !== null) { |
||
| 23 | $remember = $request->cookie($user->getRememberDeviceKey()); |
||
| 24 | // If tokens do not match, cookie is no longer valid. |
||
| 25 | if ($remember !== null && $remember !== $user->getRememberDeviceToken()) { |
||
| 26 | Cookie::queue( |
||
| 27 | Cookie::forget($user->getRememberDeviceKey()) |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | |||
| 31 | if ($authenticator->isAuthenticated() || ($remember !== null && $remember === $user->getRememberDeviceToken())) { |
||
| 32 | if (!$authenticator->isAuthenticated()) { |
||
| 33 | Log::notice('User skipped OTP entry with known device.', ['id' => $request->user()->id]); |
||
| 34 | $authenticator->login(); |
||
| 35 | } |
||
| 36 | return $next($request); |
||
| 37 | } |
||
| 38 | } else { |
||
| 39 | if ($authenticator->isAuthenticated()) { |
||
| 40 | return $next($request); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | // Unlike \PragmaRX\Google2FALaravel\Middleware, set the intended url. |
||
| 45 | // Check if the intended url already exists, if not then store in global session. |
||
| 46 | if (!session()->has('url.expected')) { |
||
| 47 | Session::put('url.expected', URL::full()); |
||
| 48 | } |
||
| 49 | return $authenticator->makeRequestOneTimePasswordResponse(); |
||
| 50 | } |
||
| 52 |