AuthMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bludata\Lumen\Authentication\JWT\Middleware;
4
5
use Bludata\Lumen\Authentication\JWT\Exceptions\RestrictAccessException;
6
use Closure;
7
use Illuminate\Contracts\Auth\Factory as Auth;
8
9
final class AuthMiddleware
10
{
11
    protected $auth;
12
13
    public function __construct(Auth $auth)
14
    {
15
        $this->auth = $auth;
16
    }
17
18
    /**
19
     * Handle an incoming request.
20
     *
21
     * @param \Illuminate\Http\Request $request
22
     * @param \Closure                 $next
23
     *
24
     * @return mixed
25
     */
26
    public function handle($request, Closure $next, $guard = null)
27
    {
28
        try {
29
            if ($this->auth->guard($guard)->guest()) {
30
                throw new RestrictAccessException();
31
            }
32
33
            return $next($request);
34
        } catch (RestrictAccessException $e) {
35
            abort(401, $e->getMessage());
36
        }
37
    }
38
}
39