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