Total Complexity | 2 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
22 | trait PatchMethod |
||
23 | { |
||
24 | /** |
||
25 | * Generic 'patchMethod' method for REST resources. |
||
26 | * |
||
27 | * @param array<int, string>|null $allowedHttpMethods |
||
28 | * |
||
29 | * @throws Throwable |
||
30 | */ |
||
31 | 12 | public function patchMethod( |
|
32 | Request $request, |
||
33 | RestDtoInterface $restDto, |
||
34 | string $id, |
||
35 | ?array $allowedHttpMethods = null, |
||
36 | ): Response { |
||
|
|||
37 | 12 | $resource = $this->getResourceForMethod($request, $allowedHttpMethods ?? ['PATCH']); |
|
38 | |||
39 | try { |
||
40 | 3 | $data = $resource->patch($id, $restDto, true); |
|
41 | |||
42 | 2 | return $this->getResponseHandler()->createResponse($request, $data, $resource); |
|
43 | 1 | } catch (Throwable $exception) { |
|
44 | 1 | throw $this->handleRestMethodException($exception, $id); |
|
45 | } |
||
48 |