Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ListBooksController
100.00% covered (success)
100.00%
5 / 5
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%
4 / 4
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\ListBooksQuery;
13use AppDemo\Library\Presentation\ListBooksJsonPresenter;
14use Phexium\Application\AbstractApiController;
15use Phexium\Application\ControllerInterface;
16use Phexium\Plugin\QueryBus\Port\QueryBusInterface;
17use Phexium\Presentation\ResponseBuilderInterface;
18use Psr\Http\Message\ResponseInterface;
19use Psr\Http\Message\ServerRequestInterface;
20
21final readonly class ListBooksController extends AbstractApiController implements ControllerInterface
22{
23    public function __construct(
24        private QueryBusInterface $queryBus,
25        private ListBooksJsonPresenter $presenter,
26        protected ResponseBuilderInterface $responseBuilder,
27    ) {}
28
29    public function index(
30        ServerRequestInterface $request, // NOSONAR - Slim Framework PSR-15 contract
31        ResponseInterface $response
32    ): ResponseInterface {
33        $query = new ListBooksQuery();
34
35        $queryResponse = $this->queryBus->dispatch($query);
36
37        $viewModel = $this->presenter->present($queryResponse)->getViewModel();
38
39        return $this->jsonSuccess($response, $viewModel);
40    }
41}