Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DetailBookController | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
5 / 5 |
|
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 AppDemo\Library\Application\Api; |
| 11 | |
| 12 | use AppDemo\Library\Application\Query\DetailBookQuery; |
| 13 | use AppDemo\Library\Presentation\DetailBookJsonPresenter; |
| 14 | use Phexium\Application\AbstractApiController; |
| 15 | use Phexium\Application\ControllerInterface; |
| 16 | use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface; |
| 17 | use Phexium\Plugin\QueryBus\Port\QueryBusInterface; |
| 18 | use Phexium\Presentation\ResponseBuilderInterface; |
| 19 | use Psr\Http\Message\ResponseInterface; |
| 20 | use Psr\Http\Message\ServerRequestInterface; |
| 21 | |
| 22 | final readonly class DetailBookController extends AbstractApiController implements ControllerInterface |
| 23 | { |
| 24 | public function __construct( |
| 25 | private QueryBusInterface $queryBus, |
| 26 | private DetailBookJsonPresenter $presenter, |
| 27 | protected ResponseBuilderInterface $responseBuilder, |
| 28 | private IdGeneratorInterface $idGenerator, |
| 29 | ) {} |
| 30 | |
| 31 | public function index( |
| 32 | ServerRequestInterface $request, // NOSONAR - Slim Framework PSR-15 contract |
| 33 | ResponseInterface $response, |
| 34 | array $args = [] |
| 35 | ): ResponseInterface { |
| 36 | $bookId = $this->idGenerator->from($args['id']); |
| 37 | $query = new DetailBookQuery($bookId); |
| 38 | |
| 39 | $queryResponse = $this->queryBus->dispatch($query); |
| 40 | |
| 41 | $viewModel = $this->presenter->present($queryResponse)->getViewModel(); |
| 42 | |
| 43 | return $this->jsonSuccess($response, $viewModel); |
| 44 | } |
| 45 | } |