Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 4
1
<?php
2
3
namespace LearnParty\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class Authenticate
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @codeCoverageIgnore
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @param  \Closure  $next
17
     * @param  string|null  $guard
18
     * @return mixed
19
     */
20
    public function handle($request, Closure $next, $guard = null)
21
    {
22
        if (Auth::guard($guard)->guest()) {
23
            if ($request->ajax() || $request->wantsJson()) {
24
                return response('Unauthorized.', 401);
25
            } else {
26
                return redirect()->guest('login');
27
            }
28
        }
29
30
        return $next($request);
31
    }
32
}
33