Completed
Push — master ( dfe268...3e25db )
by Brian
15s queued 12s
created

RedirectIfNotSeller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
ccs 3
cts 8
cp 0.375
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 3
1
<?php
2
3
namespace App\Modules\Sellers\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Auth\AuthenticationException;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Auth;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * @see \Http\Middleware\Authenticate
13
 */
14
class RedirectIfNotSeller
15
{
16
    /**
17
     * Handle an incoming request.
18
     *
19
     * @throws \Illuminate\Auth\AuthenticationException
20
     */
21 15
    public function handle(Request $request, Closure $next, string $guard = 'seller'): Response
22
    {
23 15
        if (Auth::guard($guard)->check()) {
24 15
            return $next($request);
25
        }
26
27
        $redirectToRoute = $request->expectsJson() ? '' : route('seller.login');
28
29
        throw new AuthenticationException(
30
            'Unauthenticated.',
31
            [$guard],
32
            $redirectToRoute
33
        );
34
    }
35
}
36