Authenticate::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.4286
cc 3
eloc 7
nc 3
nop 2
1
<?php namespace WITR\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
	 * @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...
20
	 */
21
	public function __construct(Guard $auth)
22
	{
23
		$this->auth = $auth;
24
	}
25
26
	/**
27
	 * Handle an incoming request.
28
	 *
29
	 * @param  \Illuminate\Http\Request  $request
30
	 * @param  \Closure  $next
31
	 * @return mixed
32
	 */
33
	public function handle($request, Closure $next)
34
	{
35
		if ($this->auth->guest())
36
		{
37
			if ($request->ajax())
38
			{
39
				return response('Unauthorized.', 401);
40
			}
41
			else
42
			{
43
				return redirect()->guest('auth/login');
44
			}
45
		}
46
47
		return $next($request);
48
	}
49
50
}
51