Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListBooksHandler | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
2 | |||
| 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\Library\Application\Query; |
| 11 | |
| 12 | use AppDemo\Library\Domain\BookRepository; |
| 13 | use Override; |
| 14 | use Phexium\Application\Query\AbstractQueryHandler; |
| 15 | use Phexium\Application\Query\QueryHandlerInterface; |
| 16 | use Phexium\Application\Query\QueryInterface; |
| 17 | use Phexium\Application\Query\QueryResponseInterface; |
| 18 | use Phexium\Domain\TypeGuard; |
| 19 | |
| 20 | final class ListBooksHandler extends AbstractQueryHandler implements QueryHandlerInterface |
| 21 | { |
| 22 | public function __construct( |
| 23 | private readonly BookRepository $bookRepository |
| 24 | ) {} |
| 25 | |
| 26 | #[Override] |
| 27 | public function handle(QueryInterface $query): QueryResponseInterface |
| 28 | { |
| 29 | TypeGuard::that($query)->isInstanceOf(ListBooksQuery::class); |
| 30 | |
| 31 | $books = $this->bookRepository->findAll(); |
| 32 | |
| 33 | $bookItems = []; |
| 34 | |
| 35 | foreach ($books as $book) { |
| 36 | $bookItems[] = [ |
| 37 | 'id' => $book->getId()->getValue(), |
| 38 | 'title' => $book->getTitle()->getValue(), |
| 39 | 'author' => $book->getAuthor()->getValue(), |
| 40 | 'isbn' => $book->getIsbn()->getFormattedValue(), |
| 41 | 'status' => $book->getStatus()->value, |
| 42 | ]; |
| 43 | } |
| 44 | |
| 45 | return new ListBooksResponse($bookItems); |
| 46 | } |
| 47 | } |