Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListLoansController | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
14 / 14 |
|
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\Presentation\Http; |
| 11 | |
| 12 | use AppDemo\Loan\Application\Query\ListLoansQuery; |
| 13 | use AppDemo\Loan\Presentation\ListLoansHtmlPresenter; |
| 14 | use AppDemo\Shared\Presentation\AbstractHttpController; |
| 15 | use Phexium\Plugin\QueryBus\Port\QueryBusInterface; |
| 16 | use Phexium\Presentation\ControllerInterface; |
| 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, |
| 33 | ResponseInterface $response |
| 34 | ): ResponseInterface { |
| 35 | $page = max(1, (int) ($request->getQueryParams()['page'] ?? 1)); |
| 36 | |
| 37 | $query = new ListLoansQuery(page: $page); |
| 38 | |
| 39 | $queryResponse = $this->queryBus->dispatch($query); |
| 40 | |
| 41 | $viewModel = $this->presenter |
| 42 | ->present($queryResponse) |
| 43 | ->getViewModel() |
| 44 | ; |
| 45 | |
| 46 | $html = $this->twig->render('ListLoans.html.twig', (array) $viewModel); |
| 47 | |
| 48 | return $this->responseBuilder |
| 49 | ->withResponse($response) |
| 50 | ->withStatus(200) |
| 51 | ->withHtml($html) |
| 52 | ->build() |
| 53 | ; |
| 54 | } |
| 55 | } |