Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

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