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
BorrowBookHandler
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
4
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
3
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\Library\Domain\BookRepository;
13use Phexium\Application\Query\QueryHandlerInterface;
14
15final readonly class BorrowBookHandler implements QueryHandlerInterface
16{
17    public function __construct(
18        private BookRepository $bookRepository
19    ) {}
20
21    public function __invoke(BorrowBookQuery $query): BorrowBookResponse
22    {
23        $allBooks = $this->bookRepository->findAll();
24        $availableBooks = [];
25
26        foreach ($allBooks as $book) {
27            if ($book->getStatus()->isAvailable()) {
28                $availableBooks[] = [
29                    'id' => $book->getId()->getValue(),
30                    'title' => $book->getTitle()->getValue(),
31                    'author' => $book->getAuthor()->getValue(),
32                    'isbn' => $book->getIsbn()->getValue(),
33                ];
34            }
35        }
36
37        return new BorrowBookResponse(
38            $availableBooks,
39            $query->formValues,
40            $query->errors
41        );
42    }
43}