Completed
Pull Request — master (#141)
by
unknown
02:33
created

Admin::handle()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
rs 8.8571
cc 5
eloc 9
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')
21
            ?: config('auth.defaults.guard');
22
23
        if (Auth::guard($guard)->guest()) {
24
            if ($request->ajax() || $request->wantsJson()) {
25
                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...
26
            } else {
27
                return redirect()->guest(config('backpack.base.route_prefix', 'admin').'/login');
28
            }
29
        }
30
31
        return $next($request);
32
    }
33
}
34