Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 39
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 3
1
<?php
2
3
namespace plunner\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
     * @return mixed
33
     */
34
    public function handle($request, Closure $next)
35
    {
36
        if ($this->auth->guest()) {
37
            if ($request->ajax()) {
38
                return response('Unauthorized.', 401);
39
            } else {
40
                return redirect()->guest('auth/login');
41
            }
42
        }
43
44
        return $next($request);
45
    }
46
}
47