Conditions | 4 |
Paths | 6 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 4.0218 |
Changes | 0 |
1 | <?php |
||
14 | 23 | public function __invoke(Request $request, Response $response, Application $app) |
|
15 | { |
||
16 | 23 | $requestMethod = $app["request_context"]->getMethod(); |
|
17 | 23 | $app["request_context"]->setMethod("NOTAMETHOD"); |
|
18 | |||
19 | try { |
||
20 | 23 | $app["request_matcher"]->match($request->getPathInfo()); |
|
21 | $allow = []; // Should never get here |
||
22 | 23 | } catch (MethodNotAllowedException $e) { |
|
23 | 23 | $allow = array_filter($e->getAllowedMethods(), function ($method) { |
|
24 | 23 | return $method != "OPTIONS"; |
|
25 | 23 | }); |
|
26 | } catch (ResourceNotFoundException $e) { |
||
27 | $allow = []; // Should never get here |
||
28 | } |
||
29 | |||
30 | $app["request_context"]->setMethod($requestMethod); |
||
31 | |||
32 | if (count($allow) === 0) { |
||
33 | throw new NotFoundHttpException(); |
||
34 | } |
||
35 | |||
36 | $response->headers->set("Allow", implode(",", $allow)); |
||
37 | |||
38 | return $response; |
||
39 | } |
||
40 | } |
||
41 |