Skip to content

Instantly share code, notes, and snippets.

@imanghafoori1
Last active February 22, 2018 16:47
Show Gist options
  • Save imanghafoori1/50c30d33d48ccae62165d9ec763b379e to your computer and use it in GitHub Desktop.
Save imanghafoori1/50c30d33d48ccae62165d9ec763b379e to your computer and use it in GitHub Desktop.
<?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