Authenticate::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Http\Request;
8
9
class Authenticate
10
{
11
    protected $auth;
12
13
    public function __construct(Guard $auth)
14
    {
15
        $this->auth = $auth;
16
    }
17
18
    public function handle(Request $request, Closure $next)
19
    {
20
        if ($this->auth->guest()) {
21
            if ($request->ajax() || $request->route()->getName() === 'play') {
22
                return response('Unauthorized.', 401);
23
            } else {
24
                return redirect()->guest('login');
25
            }
26
        }
27
28
        return $next($request);
29
    }
30
}
31