RedirectIfAuthenticated::handle()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 6
nop 3
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 4
rs 10
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