Authenticate::__construct()   A
last analyzed

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