Completed
Push — master ( 8e331c...74e133 )
by Ryan
78:29
created

Authenticate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Anomaly\Streams\Platform\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Contracts\Auth\Guard;
5
6
/**
7
 * Class Authenticate
8
 *
9
 * @link          http://pyrocms.com/
10
 * @author        PyroCMS, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\Streams\Platform\Http\Middleware
13
 */
14
class Authenticate
15
{
16
17
    /**
18
     * The Guard implementation.
19
     *
20
     * @var Guard
21
     */
22
    protected $auth;
23
24
    /**
25
     * Create a new filter instance.
26
     *
27
     * @param  Guard $auth
28
     * @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...
29
     */
30
    public function __construct(Guard $auth)
31
    {
32
        $this->auth = $auth;
33
    }
34
35
    /**
36
     * Handle an incoming request.
37
     *
38
     * @param  \Illuminate\Http\Request $request
39
     * @param  \Closure                 $next
40
     * @return mixed
41
     */
42
    public function handle($request, Closure $next)
43
    {
44
        if ($this->auth->guest()) {
45
            if ($request->ajax()) {
46
                return response('Unauthorized.', 401);
47
            } else {
48
                return redirect()->guest('auth/login');
49
            }
50
        }
51
52
        return $next($request);
53
    }
54
}
55