Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ListLoansController
100.00% covered (success)
100.00%
15 / 15
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%
14 / 14
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\Loan\Presentation\Http;
11
12use AppDemo\Loan\Application\Query\ListLoansQuery;
13use AppDemo\Loan\Presentation\ListLoansHtmlPresenter;
14use AppDemo\Shared\Presentation\AbstractHttpController;
15use Phexium\Plugin\QueryBus\Port\QueryBusInterface;
16use Phexium\Presentation\ControllerInterface;
17use Phexium\Presentation\ResponseBuilderInterface;
18use Psr\Http\Message\ResponseInterface;
19use Psr\Http\Message\ServerRequestInterface;
20use Twig\Environment;
21
22final 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}