Last active
February 22, 2018 16:47
-
-
Save imanghafoori1/50c30d33d48ccae62165d9ec763b379e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AuthController { | |
public function login(Request $request) | |
{ | |
$validator = Validator::make($request->all(), [ | |
'email' => 'required|max:255||string', | |
'password' => 'required|confirmed||string', | |
]); | |
if ($validator->fails()) { | |
return redirect('/some-where')->withErrors($validator)->withInput(); | |
} | |
if ($this->hasTooManyLoginAttempts($request)) { | |
$this->fireLockoutEvent($request); | |
return $this->sendLockoutResponse($request); | |
} | |
if ($this->attemptLogin($request)) { | |
return $this->sendLoginResponse($request); | |
} | |
$this->incrementLoginAttempts($request); | |
return $this->sendFailedLoginResponse($request); | |
} | |
} | |
``` | |
Look at the above code and all it's branching if statements. | |
It is just trivial example. it is as much as we can refactor the controller method because we are forced to return something. | |
(throwing exceptions may help but they can quickly become confusing since we are never sure where the handler is sitting.) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment