Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UpdateBookHandler | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
11 / 11 |
|
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\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 UpdateBookHandler 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(UpdateBookQuery::class); |
| 30 | |
| 31 | $book = $this->bookRepository->getById($query->bookId); |
| 32 | |
| 33 | return new UpdateBookQueryResponse( |
| 34 | $book->getId()->getValue(), |
| 35 | $book->getTitle()->getValue(), |
| 36 | $book->getAuthor()->getValue(), |
| 37 | $book->getIsbn()->getFormattedValue(), |
| 38 | $book->getStatus()->value, |
| 39 | $query->formValues, |
| 40 | $query->errors |
| 41 | ); |
| 42 | } |
| 43 | } |