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 |
||
23 | 160 | public function handle(Request $request, Closure $next) |
|
24 | { |
||
25 | 160 | $route = $request->route(); |
|
26 | |||
27 | 160 | if (!$route) { |
|
28 | #TODO: Invoke the default callback. |
||
29 | return abort(401); |
||
30 | } |
||
31 | |||
32 | 160 | $constraint = $route->getAction('geo') ?? []; |
|
33 | |||
34 | 160 | $validator = Validator::make($constraint, [ |
|
35 | 160 | 'countries' => 'required|array|min:1', |
|
36 | 'countries.*' => 'string|min:2|max:2', |
||
37 | 'strategy' => 'required|in:allow,deny', |
||
38 | ]); |
||
39 | |||
40 | 160 | if ($validator->fails()) { |
|
41 | 16 | throw new Exception("The GeoRoute constraint is invalid."); |
|
42 | } |
||
43 | |||
44 | 144 | if ($this->shouldHaveAccess((array)$constraint['countries'], $constraint['strategy'])) { |
|
45 | 16 | return $next($request); |
|
46 | } |
||
47 | |||
48 | 128 | if (array_key_exists('callback', $constraint) && $callback = $constraint['callback']) { |
|
49 | 80 | return call_user_func_array($callback[0], $callback[1]); |
|
50 | } |
||
51 | |||
52 | 48 | return abort(401); |
|
53 | } |
||
55 |