Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
BookRepositoryMappingTrait
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rowToBook
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 bookToRow
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\Trait;
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;
17
18trait BookRepositoryMappingTrait
19{
20    protected function rowToBook(array $row): Book
21    {
22        return new Book(
23            $this->idGenerator->from($row['id']),
24            Title::fromString($row['title']),
25            Author::fromString($row['author']),
26            ISBN::fromString($row['isbn']),
27            BookStatus::from($row['status'])
28        );
29    }
30
31    protected function bookToRow(Book $book): array
32    {
33        return [
34            'id' => $book->getId()->getValue(),
35            'title' => $book->getTitle()->getValue(),
36            'author' => $book->getAuthor()->getValue(),
37            'isbn' => $book->getIsbn()->getValue(),
38            'status' => $book->getStatus()->value,
39        ];
40    }
41}