Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 15 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
			} else
40
			{
41
				return redirect()->guest('auth/login');
42
			}
43
		}
44
45
		return $next($request);
46
	}
47
48
}
49