Authenticate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Factory as Auth;
7
8
class Authenticate
9
{
10
    /**
11
     * The authentication guard factory instance.
12
     *
13
     * @var \Illuminate\Contracts\Auth\Factory
14
     */
15
    protected $auth;
16
17
    /**
18
     * Create a new middleware instance.
19
     *
20
     * @param \Illuminate\Contracts\Auth\Factory $auth
21
     *
22
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
23
     */
24
    public function __construct(Auth $auth)
25
    {
26
        $this->auth = $auth;
27
    }
28
29
    /**
30
     * Handle an incoming request.
31
     *
32
     * @param \Illuminate\Http\Request $request
33
     * @param \Closure                 $next
34
     * @param string|null              $guard
35
     *
36
     * @return mixed
37
     */
38
    public function handle($request, Closure $next, $guard = null)
39
    {
40
        if ($this->auth->guard($guard)->guest()) {
41
            return response('Unauthorized.', 401);
42
        }
43
44
        return $next($request);
45
    }
46
}
47