Fix "CleanCode/ElseExpression" issue in app/Http/Middleware/Authenticate.php
alariva opened this issue · 2 comments
This issue is not that hard, and I've opened it as an invitation for first-timers to jump-in the project and do their first contribution.
That means that I will only accept a PR (Pull Request) for this one from someone who's never contributed to open source before. This one is particularly easy (but don't make that statement make you feel bad if you have a hard time with it, there's more to contributing to open source than changing lines of code, especially if it's your first time). I'll hold your hand through this if you need me to. :-)
Don't worry, I'll be happy to help you with:
- Installing timegrid on your local environment for development
- Explaining the basics about the application and how it works
- Run tests
- Change the code and run the tests again
- Commit the changes and push to your fork
- Create a PR
Just reach me on gitter
The issue
The method handle uses an else expression. Else is never necessary and you can simplify the code to work without else.
So basically, since both branches of the if
are returning, the code can be changed from this
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('/login');
}
}
return $next($request);
}
to this
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
return redirect()->guest('/login');
}
return $next($request);
}
Hi , @alariva I am very new to Open source, would love to contribute, and would need your help in doing so
Hi @Kashyap12 , thanks! Please reach out our Gitter channel and we may discuss on getting started.