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

Admin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 3
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 14 5
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