Passed
Push — master ( 75052b...8ecf83 )
by Dmitri
01:50
created

Book   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Domain\Model;
6
7
use App\Domain\Event\BookCreated;
8
use DateTimeImmutable;
9
use DateTimeInterface;
10
use SimpleBus\Message\Recorder\ContainsRecordedMessages;
11
use SimpleBus\Message\Recorder\PrivateMessageRecorderCapabilities;
12
13
class Book implements ContainsRecordedMessages
14
{
15
    use PrivateMessageRecorderCapabilities;
16
17
    private $id;
18
    private $authorId;
19
    private $title;
20
    private $createdAt;
21
22
    public function __construct(BookId $id, AuthorId $authorId, string $title)
23
    {
24
        $this->id = (string) $id;
25
        $this->authorId = (string) $authorId;
26
        $this->title = $title;
27
        $this->createdAt = new DateTimeImmutable();
28
29
        $this->record(new BookCreated($id, $authorId, $title, $this->createdAt));
30
    }
31
32
    public function id(): BookId
33
    {
34
        return BookId::fromString((string) $this->id);
35
    }
36
37
    public function authorId(): AuthorId
38
    {
39
        return AuthorId::fromString((string) $this->authorId);
40
    }
41
42
    public function title(): string
43
    {
44
        return $this->title;
45
    }
46
47
    public function createdAt(): DateTimeInterface
48
    {
49
        return $this->createdAt;
50
    }
51
}
52