Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
BookMapper
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
3 / 3
3
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
 fromRow
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 toRow
100.00% covered (success)
100.00%
7 / 7
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\Infrastructure\Mapper;
11
12use AppDemo\Library\Domain\Author;
13use AppDemo\Library\Domain\Book;
14use AppDemo\Library\Domain\BookStatus;
15use AppDemo\Library\Domain\ISBN;
16use AppDemo\Library\Domain\Title;
17use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface;
18
19final readonly class BookMapper
20{
21    public function __construct(
22        private IdGeneratorInterface $idGenerator,
23    ) {}
24
25    public function fromRow(array $row): Book
26    {
27        return new Book(
28            $this->idGenerator->from($row['id']),
29            Title::fromString($row['title']),
30            Author::fromString($row['author']),
31            ISBN::fromString($row['isbn']),
32            BookStatus::from($row['status'])
33        );
34    }
35
36    public function toRow(Book $book): array
37    {
38        return [
39            'id' => $book->getId()->getValue(),
40            'title' => $book->getTitle()->getValue(),
41            'author' => $book->getAuthor()->getValue(),
42            'isbn' => $book->getIsbn()->getValue(),
43            'status' => $book->getStatus()->value,
44        ];
45    }
46}