Conditions | 4 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 18 |
Ratio | 100 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
17 | public function handle($request, Closure $next, $role) |
||
18 | { |
||
19 | if (! $request->user() || ! $request->user()->isRole($role)) { |
||
20 | if ($request->ajax()) { |
||
21 | return response()->json([ |
||
22 | 'error' => [ |
||
23 | 'status_code' => 401, |
||
24 | 'code' => 'INSUFFICIENT_PERMISSIONS', |
||
25 | 'description' => 'You are not authorized to access this resource.', |
||
26 | ], |
||
27 | ], 401); |
||
28 | } |
||
29 | |||
30 | return abort(401, 'You are not authorized to access this resource.'); |
||
31 | } |
||
32 | |||
33 | return $next($request); |
||
34 | } |
||
35 | } |
||
36 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.