Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DetailBookController
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
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
8declare(strict_types=1);
9
10namespace AppDemo\Library\Application\Api;
11
12use AppDemo\Library\Application\Query\DetailBookQuery;
13use AppDemo\Library\Presentation\DetailBookJsonPresenter;
14use Phexium\Application\AbstractApiController;
15use Phexium\Application\ControllerInterface;
16use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface;
17use Phexium\Plugin\QueryBus\Port\QueryBusInterface;
18use Phexium\Presentation\ResponseBuilderInterface;
19use Psr\Http\Message\ResponseInterface;
20use Psr\Http\Message\ServerRequestInterface;
21
22final 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}