Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListBooksController | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
4 / 4 |
|
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\ListBooksQuery; |
| 13 | use AppDemo\Library\Presentation\ListBooksJsonPresenter; |
| 14 | use Phexium\Application\AbstractApiController; |
| 15 | use Phexium\Application\ControllerInterface; |
| 16 | use Phexium\Plugin\QueryBus\Port\QueryBusInterface; |
| 17 | use Phexium\Presentation\ResponseBuilderInterface; |
| 18 | use Psr\Http\Message\ResponseInterface; |
| 19 | use Psr\Http\Message\ServerRequestInterface; |
| 20 | |
| 21 | final 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 | } |