RoleMiddleware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 4
1
<?php
2
3
namespace Spatie\Permission\Middlewares;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
use Spatie\Permission\Exceptions\UnauthorizedException;
8
9
class RoleMiddleware
10
{
11
    public function handle($request, Closure $next, $role, $guard = null)
12
    {
13
        if (Auth::guard($guard)->guest()) {
14
            throw UnauthorizedException::notLoggedIn();
15
        }
16
17
        $roles = is_array($role)
18
            ? $role
19
            : explode('|', $role);
20
21
        if (! Auth::guard($guard)->user()->hasAnyRole($roles)) {
22
            throw UnauthorizedException::forRoles($roles);
23
        }
24
25
        return $next($request);
26
    }
27
}
28