| Conditions | 4 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | 4 | public function __invoke(Application $app, Request $request, $id) |
|
| 13 | { |
||
| 14 | 4 | $store = $this->getStore($app); |
|
| 15 | |||
| 16 | 4 | $requestJson = $request->getContent() ?: "{}"; |
|
| 17 | 4 | $data = json_decode($requestJson); |
|
| 18 | |||
| 19 | 4 | $this->validate($app, $id, $data); |
|
| 20 | |||
| 21 | 3 | $isCreated = !$store->contains($request->getRequestUri()); |
|
| 22 | 3 | if ($store->save($request->getRequestUri(), $data) === false) { |
|
| 23 | 1 | throw new ServiceUnavailableHttpException(null, "Failed to save resource"); |
|
| 24 | } |
||
| 25 | |||
| 26 | 2 | return $app->json($data,$isCreated?201:200); |
|
| 27 | } |
||
| 28 | |||
| 30 |