| Conditions | 8 |
| Paths | 8 |
| Total Lines | 53 |
| Code Lines | 31 |
| 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 |
||
| 97 | protected function getLoginResponse(Request $request, $result) |
||
| 98 | { |
||
| 99 | switch ($result) { |
||
| 100 | // Too many failed logins, user locked out |
||
| 101 | case SessionGuard::AUTH_LOCKED_OUT: |
||
| 102 | $seconds = Auth::guard($this->getGuard())->secondsRemainingOnLockout($request); |
||
| 103 | |||
| 104 | return intend([ |
||
| 105 | 'intended' => route('home'), |
||
| 106 | 'withInput' => $request->only('loginfield', 'remember'), |
||
| 107 | 'withErrors' => ['loginfield' => Lang::get($result, ['seconds' => $seconds])], |
||
| 108 | ]); |
||
| 109 | |||
| 110 | // Valid credentials, but user is unverified; Can NOT login! |
||
| 111 | case SessionGuard::AUTH_UNVERIFIED: |
||
| 112 | return intend([ |
||
| 113 | 'intended' => route('rinvex.fort.verification.email'), |
||
| 114 | 'withErrors' => ['email' => Lang::get($result)], |
||
| 115 | ]); |
||
| 116 | |||
| 117 | // Valid credentials, but user is moderated; Can NOT login! |
||
| 118 | case SessionGuard::AUTH_MODERATED: |
||
| 119 | return intend([ |
||
| 120 | 'home' => true, |
||
| 121 | 'withErrors' => ['rinvex.fort.auth.moderated' => Lang::get($result)], |
||
| 122 | ]); |
||
| 123 | |||
| 124 | // Wrong credentials, failed login |
||
| 125 | case SessionGuard::AUTH_FAILED: |
||
| 126 | return intend([ |
||
| 127 | 'back' => true, |
||
| 128 | 'withInput' => $request->only('loginfield', 'remember'), |
||
| 129 | 'withErrors' => ['loginfield' => Lang::get($result)], |
||
| 130 | ]); |
||
| 131 | |||
| 132 | // Two-Factor authentication required |
||
| 133 | case SessionGuard::AUTH_TWOFACTOR_REQUIRED: |
||
| 134 | $route = ! isset(session('rinvex.fort.twofactor.methods')['totp']) ? 'rinvex.fort.verification.phone' : 'rinvex.fort.verification.phone.verify'; |
||
| 135 | |||
| 136 | return intend([ |
||
| 137 | 'route' => $route, |
||
| 138 | 'with' => ['rinvex.fort.alert.warning' => Lang::get($result)], |
||
| 139 | ]); |
||
| 140 | |||
| 141 | // Login successful and everything is fine! |
||
| 142 | case SessionGuard::AUTH_LOGIN: |
||
| 143 | default: |
||
| 144 | return intend([ |
||
| 145 | 'intended' => route('home'), |
||
| 146 | 'with' => ['rinvex.fort.alert.success' => Lang::get($result)], |
||
| 147 | ]); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.