Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DetailBookHandler
100.00% covered (success)
100.00%
10 / 10
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
 handle
100.00% covered (success)
100.00%
9 / 9
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\Library\Application\Query;
11
12use AppDemo\Library\Domain\BookRepository;
13use Override;
14use Phexium\Application\Query\AbstractQueryHandler;
15use Phexium\Application\Query\QueryHandlerInterface;
16use Phexium\Application\Query\QueryInterface;
17use Phexium\Application\Query\QueryResponseInterface;
18use Phexium\Domain\TypeGuard;
19
20final class DetailBookHandler 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(DetailBookQuery::class);
30
31        $book = $this->bookRepository->getById($query->id);
32
33        return new DetailBookResponse(
34            $book->getId()->getValue(),
35            $book->getTitle()->getValue(),
36            $book->getAuthor()->getValue(),
37            $book->getIsbn()->getFormattedValue(),
38            $book->getStatus()->value,
39        );
40    }
41}