Authenticate   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
c 0
b 0
f 0
dl 0
loc 20
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 11 4
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