Role::handle()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 3.072
rs 10
1
<?php
2
3
namespace Helldar\Roles\Http\Middleware;
4
5
use Closure;
6
use Helldar\Roles\Exceptions\Http\RoleAccessIsDeniedHttpException;
7
8
class Role extends BaseMiddleware
9
{
10
    /**
11
     * Checks for the occurrence of one of the specified roles.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  Closure  $next
15
     * @param  string  ...$roles
16
     *
17
     * @throws \Helldar\Roles\Exceptions\Http\RoleAccessIsDeniedHttpException
18
     *
19
     * @return mixed
20
     */
21 30
    public function handle($request, Closure $next, ...$roles)
22
    {
23 30
        $this->check();
24
25 18
        if ($this->hasRoot($request) || $request->user()->hasRole($roles)) {
26 18
            return $next($request);
27
        }
28
29
        throw new RoleAccessIsDeniedHttpException();
30
    }
31
}
32