Completed
Pull Request — master (#259)
by Cristian
02:13
created

CheckIfAdmin::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 12
rs 9.2
1
<?php
2
3
namespace Backpack\Base\app\Http\Middleware;
4
5
use Closure;
6
7
class CheckIfAdmin
8
{
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param \Illuminate\Http\Request $request
13
     * @param \Closure                 $next
14
     *
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next)
18
    {
19
        if (backpack_auth()->guest()) {
20
            if ($request->ajax() || $request->wantsJson()) {
21
                return response(trans('backpack::base.unauthorized'), 401);
22
            } else {
23
                return redirect()->guest(backpack_url('login'));
0 ignored issues
show
Bug introduced by
It seems like backpack_url('login') targeting backpack_url() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, Illuminate\Routing\Redirector::guest() 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
            }
25
        }
26
27
        return $next($request);
28
    }
29
}
30