Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
Book
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
8 / 8
10
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
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIsbn
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 markAsBorrowed
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 markAsAvailable
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
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\Domain;
11
12use AppDemo\Library\Domain\Exception\BookNotAvailableException;
13use Phexium\Domain\EntityAbstract;
14use Phexium\Domain\EntityInterface;
15use Phexium\Domain\Id\IdInterface;
16
17final class Book extends EntityAbstract implements EntityInterface
18{
19    public function __construct(
20        private readonly IdInterface $id,
21        private readonly Title $title,
22        private readonly Author $author,
23        private readonly ISBN $isbn,
24        private BookStatus $status = BookStatus::Available
25    ) {}
26
27    public function getId(): IdInterface
28    {
29        return $this->id;
30    }
31
32    public function getTitle(): Title
33    {
34        return $this->title;
35    }
36
37    public function getAuthor(): Author
38    {
39        return $this->author;
40    }
41
42    public function getIsbn(): ISBN
43    {
44        return $this->isbn;
45    }
46
47    public function getStatus(): BookStatus
48    {
49        return $this->status;
50    }
51
52    public function markAsBorrowed(): void
53    {
54        if (!$this->status->canBeBorrowed()) {
55            throw BookNotAvailableException::forBorrowing($this->id);
56        }
57        $this->status = BookStatus::Borrowed;
58    }
59
60    public function markAsAvailable(): void
61    {
62        if (!$this->status->canBeReturned()) {
63            throw BookNotAvailableException::forReturning($this->id);
64        }
65        $this->status = BookStatus::Available;
66    }
67}