Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListBooksJsonPresenter | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| present | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| getViewModel | |
100.00% |
1 / 1 |
|
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\Presentation; |
| 11 | |
| 12 | use AppDemo\Library\Application\Query\ListBooksResponse; |
| 13 | use Override; |
| 14 | use Phexium\Presentation\PresenterAbstract; |
| 15 | use Phexium\Presentation\PresenterInterface; |
| 16 | |
| 17 | final class ListBooksJsonPresenter extends PresenterAbstract implements PresenterInterface |
| 18 | { |
| 19 | private array $jsonViewModel; |
| 20 | |
| 21 | public function present(ListBooksResponse $response): self |
| 22 | { |
| 23 | $pagination = $response->pagination; |
| 24 | |
| 25 | $this->jsonViewModel = [ |
| 26 | 'books' => $response->books, |
| 27 | 'pagination' => [ |
| 28 | 'total_count' => $pagination->totalCount, |
| 29 | 'page' => $pagination->page, |
| 30 | 'per_page' => $pagination->perPage, |
| 31 | 'total_pages' => $pagination->getTotalPages(), |
| 32 | 'has_next_page' => $pagination->hasNextPage(), |
| 33 | 'has_previous_page' => $pagination->hasPreviousPage(), |
| 34 | ], |
| 35 | ]; |
| 36 | |
| 37 | return $this; |
| 38 | } |
| 39 | |
| 40 | #[Override] |
| 41 | public function getViewModel(): array |
| 42 | { |
| 43 | return $this->jsonViewModel; |
| 44 | } |
| 45 | } |