| Conditions | 6 |
| Paths | 5 |
| Total Lines | 30 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 6.0131 |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | 84 | public function handle(Request $request, Closure $next) |
|
| 27 | { |
||
| 28 | 84 | $route = $request->route(); |
|
| 29 | |||
| 30 | 84 | if (!$route) { |
|
| 31 | #TODO: Invoke the default callback. |
||
| 32 | return abort(401); |
||
| 33 | } |
||
| 34 | |||
| 35 | 84 | $constraint = $route->getAction('geo') ?? []; |
|
| 36 | |||
| 37 | 84 | $validator = Validator::make($constraint, [ |
|
| 38 | 84 | 'countries' => 'required|array|min:1', |
|
| 39 | 'countries.*' => 'string|min:2|max:2', |
||
| 40 | 'strategy' => 'required|in:allow,deny', |
||
| 41 | ]); |
||
| 42 | |||
| 43 | 84 | if ($validator->fails()) { |
|
| 44 | 12 | throw new Exception("The GeoRoute constraint is invalid."); |
|
| 45 | } |
||
| 46 | |||
| 47 | 72 | if ($this->shouldHaveAccess((array)$constraint['countries'], $constraint['strategy'])) { |
|
| 48 | 12 | return $next($request); |
|
| 49 | } |
||
| 50 | |||
| 51 | 60 | if (array_key_exists('callback', $constraint) && $callback = $constraint['callback']) { |
|
| 52 | 36 | return call_user_func_array($callback[0], $callback[1]); |
|
| 53 | } |
||
| 54 | |||
| 55 | 24 | return abort(401); |
|
| 56 | } |
||
| 58 |