Completed
Pull Request — master (#259)
by Cristian
03:39 queued 36s
created

CheckIfAdmin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 4
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