RedirectIfAuthenticated   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 4
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use App\Providers\RouteServiceProvider;
6
use Closure;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Auth;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class RedirectIfAuthenticated
12
{
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
17
     */
18 10
    public function handle(Request $request, Closure $next, string ...$guards): Response
19
    {
20 10
        $guards = empty($guards) ? [null] : $guards;
21
22 10
        foreach ($guards as $guard) {
23 10
            if (Auth::guard($guard)->check()) {
24 1
                return redirect(RouteServiceProvider::HOME);
25
            }
26
        }
27
28 10
        return $next($request);
29
    }
30
}
31