Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListLoansController | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
10 / 10 |
|
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\Loan\Application\Http; |
| 11 | |
| 12 | use AppDemo\Loan\Application\Query\ListLoansQuery; |
| 13 | use AppDemo\Loan\Presentation\ListLoansHtmlPresenter; |
| 14 | use AppDemo\Shared\Application\AbstractHttpController; |
| 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 | use Twig\Environment; |
| 21 | |
| 22 | final readonly class ListLoansController extends AbstractHttpController implements ControllerInterface |
| 23 | { |
| 24 | public function __construct( |
| 25 | private QueryBusInterface $queryBus, |
| 26 | private ListLoansHtmlPresenter $presenter, |
| 27 | private Environment $twig, |
| 28 | private ResponseBuilderInterface $responseBuilder, |
| 29 | ) {} |
| 30 | |
| 31 | public function index( |
| 32 | ServerRequestInterface $request, // NOSONAR - Slim Framework PSR-15 contract |
| 33 | ResponseInterface $response |
| 34 | ): ResponseInterface { |
| 35 | $query = new ListLoansQuery(); |
| 36 | |
| 37 | $queryResponse = $this->queryBus->dispatch($query); |
| 38 | |
| 39 | $viewModel = $this->presenter->present($queryResponse)->getViewModel(); |
| 40 | $html = $this->twig->render('ListLoans.html.twig', (array) $viewModel); |
| 41 | |
| 42 | return $this->responseBuilder |
| 43 | ->withResponse($response) |
| 44 | ->withStatus(200) |
| 45 | ->withHtml($html) |
| 46 | ->build() |
| 47 | ; |
| 48 | } |
| 49 | } |