Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MyLoansHandler
100.00% covered (success)
100.00%
16 / 16
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
 __invoke
100.00% covered (success)
100.00%
15 / 15
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\Application\Query;
11
12use AppDemo\Loan\Domain\LoanRepository;
13use AppDemo\Loan\Domain\ReadModel\LoanWithDetails;
14use Phexium\Application\Query\QueryHandlerInterface;
15
16final readonly class MyLoansHandler implements QueryHandlerInterface
17{
18    public function __construct(
19        private LoanRepository $loanRepository,
20    ) {}
21
22    public function __invoke(MyLoansQuery $query): MyLoansResponse
23    {
24        $loansWithDetails = $this->loanRepository->findByUserIdWithBookDetails($query->userId);
25
26        $loanItems = array_map(
27            fn (LoanWithDetails $loan): array => [
28                'id' => $loan->loanId,
29                'bookId' => $loan->bookId,
30                'bookTitle' => $loan->bookTitle,
31                'borrowedAt' => $loan->borrowedAt,
32                'dueAt' => $loan->dueAt,
33                'returnedAt' => $loan->returnedAt,
34                'status' => $loan->status,
35                'isOverdue' => $loan->isOverdue,
36            ],
37            $loansWithDetails
38        );
39
40        return new MyLoansResponse($loanItems);
41    }
42}