Completed
Pull Request — master (#165)
by Cristian
02:25
created

Admin::handle()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 8.8571
c 2
b 0
f 0
cc 5
eloc 8
nc 6
nop 2
1
<?php
2
3
namespace Backpack\Base\app\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class Admin
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param \Illuminate\Http\Request $request
14
     * @param \Closure                 $next
15
     *
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        $guard = config('backpack.base.guard') ? config('backpack.base.guard') : config('auth.defaults.guard');
21
22
        if (Auth::guard($guard)->guest()) {
23
            if ($request->ajax() || $request->wantsJson()) {
24
                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<Illuminate\Contra...Translation\Translator>; 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...
25
            } else {
26
                return redirect()->guest(config('backpack.base.route_prefix', 'admin').'/login');
27
            }
28
        }
29
30
        return $next($request);
31
    }
32
}
33