Authenticate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 4
1
<?php
2
3
namespace App\Http\Middleware;
4
use Closure;
5
use Illuminate\Contracts\Auth\Guard;
6
class Authenticate
7
{
8
    /**
9
     * The Guard implementation.
10
     *
11
     * @var Guard
12
     */
13
    protected $auth;
14
    /**
15
     * Create a new filter instance.
16
     *
17
     * @param  Guard  $auth
18
     * @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...
19
     */
20
    public function __construct(Guard $auth)
21
    {
22
        $this->auth = $auth;
23
    }
24
    /**
25
     * Handle an incoming request.
26
     *
27
     * @param  \Illuminate\Http\Request  $request
28
     * @param  \Closure  $next
29
     * @return mixed
30
     */
31
    public function handle($request, Closure $next)
32
    {
33
        if ($this->auth->guest()) {
34
            if ($request->ajax() || $request->wantsJson()) {
35
                return response('Unauthorized.', 401);
36
            } else {
37
                return redirect()->guest('auth/login');
38
            }
39
        }
40
        return $next($request);
41
    }
42
}
43