VerifyLevel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 3
A __construct() 0 3 1
1
<?php
2
3
namespace Ultraware\Roles\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Http\Request;
8
use Ultraware\Roles\Exceptions\LevelDeniedException;
9
10
class VerifyLevel
11
{
12
    /**
13
     * @var Guard
14
     */
15
    protected $auth;
16
17
    /**
18
     * Create a new filter instance.
19
     *
20
     * @param Guard $auth
21
     */
22
    public function __construct(Guard $auth)
23
    {
24
        $this->auth = $auth;
25
    }
26
27
    /**
28
     * Handle an incoming request.
29
     *
30
     * @param Request $request
31
     * @param \Closure $next
32
     * @param int $level
33
     * @return mixed
34
     * @throws \Ultraware\Roles\Exceptions\LevelDeniedException
35
     */
36
    public function handle($request, Closure $next, $level)
37
    {
38
        if ($this->auth->check() && $this->auth->user()->level() >= $level) {
39
            return $next($request);
40
        }
41
42
        throw new LevelDeniedException($level);
43
    }
44
}
45