Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 3
1
<?php
2
3
namespace Colligator\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
8
class Authenticate
9
{
10
    /**
11
     * The Guard implementation.
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 \Illuminate\Http\Request $request
31
     * @param \Closure                 $next
32
     *
33
     * @return mixed
34
     */
35
    public function handle($request, Closure $next)
36
    {
37
        if ($this->auth->guest()) {
38
            if ($request->ajax()) {
39
                return response('Unauthorized.', 401);
40
            } else {
41
                return redirect()->guest('auth/login');
42
            }
43
        }
44
45
        return $next($request);
46
    }
47
}
48