Completed
Push — develop ( aa3102...ccfc23 )
by Baptiste
02:42
created

Identity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Identity\Entity;
5
6
use PersonalGalaxy\Identity\{
7
    Entity\Identity\Email,
8
    Entity\Identity\Password,
9
    Event\IdentityWasCreated,
10
    Event\Identity\PasswordWasChanged,
11
    Event\IdentityWasDeleted,
12
};
13
use Innmind\EventBus\{
14
    ContainsRecordedEventsInterface,
15
    EventRecorder,
16
};
17
18
final class Identity implements ContainsRecordedEventsInterface
19
{
20
    use EventRecorder;
21
22
    private $email;
23
    private $password;
24
25 4
    private function __construct(Email $email, Password $password)
26
    {
27 4
        $this->email = $email;
28 4
        $this->password = $password;
29 4
    }
30
31 4
    public static function create(Email $email, Password $password): self
32
    {
33 4
        $self = new self($email, $password);
34 4
        $self->record(new IdentityWasCreated($email));
35
36 4
        return $self;
37
    }
38
39 1
    public function email(): Email
40
    {
41 1
        return $this->email;
42
    }
43
44 1
    public function changePassword(Password $password): self
45
    {
46 1
        $this->password = $password;
47 1
        $this->record(new PasswordWasChanged($this->email));
48
49 1
        return $this;
50
    }
51
52 2
    public function verify(string $password): bool
53
    {
54 2
        return $this->password->verify($password);
55
    }
56
57 1
    public function delete(): void
58
    {
59 1
        $this->record(new IdentityWasDeleted($this->email));
60 1
    }
61
}
62