| Conditions | 4 | 
| Paths | 3 | 
| Total Lines | 18 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 20 | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 18 | public function handle(Request $request, Closure $next, string $permission)  | 
            ||
| 19 |     { | 
            ||
| 20 |         if (!auth()->user() || !auth()->user()->can($permission)) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 21 |             if ($request->ajax()) { | 
            ||
| 22 | return response()->json([  | 
            ||
| 23 | 'error' => [  | 
            ||
| 24 | 'status_code' => 401,  | 
            ||
| 25 | 'code' => 'INSUFFICIENT_PERMISSIONS',  | 
            ||
| 26 | 'description' => 'You are not authorized to access this resource.',  | 
            ||
| 27 | ],  | 
            ||
| 28 | ], 401);  | 
            ||
| 29 | }  | 
            ||
| 30 | |||
| 31 | abort(401, 'You are not authorized to access this resource.');  | 
            ||
| 32 | }  | 
            ||
| 33 | |||
| 34 | return $next($request);  | 
            ||
| 35 | }  | 
            ||
| 36 | }  | 
            ||
| 37 | 
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: