Agenda::identity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Calendar\Entity;
5
6
use PersonalGalaxy\Calendar\{
7
    Entity\Agenda\Identity,
8
    Entity\Agenda\User,
9
    Entity\Agenda\Name,
10
    Event\AgendaWasAdded,
11
    Event\AgendaWasRenamed,
12
    Event\AgendaWasDeleted,
13
};
14
use Innmind\EventBus\{
15
    ContainsRecordedEventsInterface,
16
    EventRecorder,
17
};
18
19
final class Agenda implements ContainsRecordedEventsInterface
20
{
21
    use EventRecorder;
22
23
    private $identity;
24
    private $user;
25
    private $name;
26
27 7
    private function __construct(Identity $identity, User $user, Name $name)
28
    {
29 7
        $this->identity = $identity;
30 7
        $this->user = $user;
31 7
        $this->name = $name;
32 7
    }
33
34 7
    public static function add(Identity $identity, User $user, Name $name): self
35
    {
36 7
        $self = new self($identity, $user, $name);
37 7
        $self->record(new AgendaWasAdded($identity, $user, $name));
38
39 7
        return $self;
40
    }
41
42 3
    public function identity(): Identity
43
    {
44 3
        return $this->identity;
45
    }
46
47 2
    public function user(): User
48
    {
49 2
        return $this->user;
50
    }
51
52 5
    public function name(): Name
53
    {
54 5
        return $this->name;
55
    }
56
57 3
    public function rename(Name $name): self
58
    {
59 3
        if ($name->equals($this->name)) {
60 1
            return $this;
61
        }
62
63 2
        $this->name = $name;
64 2
        $this->record(new AgendaWasRenamed($this->identity, $name));
65
66 2
        return $this;
67
    }
68
69
    /**
70
     * Last method that can be called, here only to record the event
71
     */
72 2
    public function delete(): void
73
    {
74 2
        $this->record(new AgendaWasDeleted($this->identity));
75 2
    }
76
}
77