Completed
Pull Request — master (#87)
by Owen
02:01
created

BackpackBaseAdmin::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 7
Ratio 58.33 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 7
nc 3
nop 3
dl 7
loc 12
rs 9.2
c 1
b 0
f 1
1
<?php
2
3
namespace Backpack\Base\app\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class BackpackBaseAdmin
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param \Illuminate\Http\Request $request
14
     * @param \Closure                 $next
15
     * @param string|null              $guard
16
     *
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next, $guard = null)
20
    {
21 View Code Duplication
        if (Auth::guard($guard)->guest()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
            if ($request->ajax() || $request->wantsJson()) {
23
                return response(trans('backpack::base.unauthorized'), 401);
0 ignored issues
show
Bug introduced by
It seems like trans('backpack::base.unauthorized') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, response() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
24
            } else {
25
                return redirect()->guest(config('backpack.base.route_prefix', 'admin').'/login');
26
            }
27
        }
28
29
        return $next($request);
30
    }
31
}
32