| Conditions | 4 |
| Paths | 3 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function handle(Request $request, Closure $next, string $role) |
||
| 20 | { |
||
| 21 | $role = Str::of($role)->split('/[|,]/')->toArray(); |
||
| 22 | if (!auth()->user() || !auth()->user()->hasRole($role)) { |
||
|
|
|||
| 23 | if ($request->ajax()) { |
||
| 24 | return response()->json([ |
||
| 25 | 'error' => [ |
||
| 26 | 'status_code' => 401, |
||
| 27 | 'code' => 'INSUFFICIENT_PERMISSIONS', |
||
| 28 | 'description' => 'You are not authorized to access this resource.', |
||
| 29 | ], |
||
| 30 | ], 401); |
||
| 31 | } |
||
| 32 | |||
| 33 | abort(401, 'You are not authorized to access this resource.'); |
||
| 34 | } |
||
| 35 | |||
| 36 | return $next($request); |
||
| 37 | } |
||
| 38 | } |
||
| 39 |
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: