Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| AbstractApiController | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| jsonSuccess | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| jsonCreated | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| jsonError | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Presentation; |
| 11 | |
| 12 | use Psr\Http\Message\ResponseInterface; |
| 13 | |
| 14 | abstract readonly class AbstractApiController extends AbstractController |
| 15 | { |
| 16 | protected ResponseBuilderInterface $responseBuilder; |
| 17 | |
| 18 | protected function jsonSuccess(ResponseInterface $response, array $payload, int $statusCode = 200): ResponseInterface |
| 19 | { |
| 20 | return $this->responseBuilder |
| 21 | ->withResponse($response) |
| 22 | ->withStatus($statusCode) |
| 23 | ->withJson($payload) |
| 24 | ->build() |
| 25 | ; |
| 26 | } |
| 27 | |
| 28 | protected function jsonCreated(ResponseInterface $response): ResponseInterface |
| 29 | { |
| 30 | return $this->responseBuilder |
| 31 | ->withResponse($response) |
| 32 | ->withStatus(201) |
| 33 | ->build() |
| 34 | ; |
| 35 | } |
| 36 | |
| 37 | protected function jsonError(ResponseInterface $response, int $statusCode, string $message): ResponseInterface |
| 38 | { |
| 39 | return $this->responseBuilder |
| 40 | ->withResponse($response) |
| 41 | ->withStatus($statusCode) |
| 42 | ->withJson(['error' => $message]) |
| 43 | ->build() |
| 44 | ; |
| 45 | } |
| 46 | } |