Agenda   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 1
A __construct() 0 5 1
A identity() 0 3 1
A delete() 0 3 1
A name() 0 3 1
A user() 0 3 1
A rename() 0 10 2
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