Passed
Push — main ( 8a25dd...3c103b )
by TARIQ
12:48
created

RedirectIfAuthenticated   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 21
c 0
b 0
f 0
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
10
class RedirectIfAuthenticated
11
{
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
17
     * @param  string|null  ...$guards
18
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
19
     */
20
    public function handle(Request $request, Closure $next, ...$guards)
21
    {
22
        $guards = empty($guards) ? [null] : $guards;
23
24
        foreach ($guards as $guard) {
25
            if (Auth::guard($guard)->check()) {
26
                return redirect(RouteServiceProvider::HOME);
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
                return /** @scrutinizer ignore-call */ redirect(RouteServiceProvider::HOME);
Loading history...
27
            }
28
        }
29
30
        return $next($request);
31
    }
32
}
33