Completed
Push — develop ( 3d08a5...0d51b0 )
by Daniel
9s
created

AdminOnly   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 4
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class AdminOnly
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request $request
14
     * @param  \Closure $next
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next, $guard = null)
18
    {
19
        if (!Auth::guard($guard)->user()->isAdmin()) {
20
            if ($request->ajax() || $request->wantsJson()) {
21
                return response(trans('general.text.unauthorized'), 401);
1 ignored issue
show
Bug introduced by
It seems like trans('general.text.unauthorized') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; 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...
22
            }
23
            else {
24
                //FIXME: Errors not working
25
                return redirect('/')->withErrors(['msg', trans('general.text.unauthorized')]);
26
            }
27
        }
28
29
        return $next($request);
30
    }
31
}
32