Passed
Push — 5.0.0 ( 8bea3a...038640 )
by Fèvre
07:16
created

RedirectIfBanished   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Auth;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class RedirectIfBanished
13
{
14
    /**
15
     * Handle an incoming request.
16
     *
17
     * @param  Closure(Request): (Response)  $next
18
     */
19
    public function handle(Request $request, Closure $next): Response
20
    {
21
        $user = Auth::user();
22
23
        if (
24
            $user &&
25
            $user->hasRole('Banished') &&
0 ignored issues
show
Bug introduced by
The method hasRole() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\GenericUser. Are you sure you never get one of those? ( Ignorable by Annotation )

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

25
            $user->/** @scrutinizer ignore-call */ 
26
                   hasRole('Banished') &&
Loading history...
26
            !$request->routeIs('page.banished')
27
        ) {
28
            return redirect()->route('page.banished');
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

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

28
            return redirect()->/** @scrutinizer ignore-call */ route('page.banished');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        }
30
31
        return $next($request);
32
    }
33
}
34