Passed
Push — feature-register_user ( a57acd...6b3ed3 )
by Laurent
05:00 queued 02:18
created

User::password()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Administration\Domain\User\Model;
4
5
use Administration\Domain\User\Model\VO\UserUuid;
6
use Core\Domain\Common\Model\VO\EmailField;
7
use Core\Domain\Common\Model\VO\NameField;
8
9
final class User
10
{
11
    private string $uuid;
12
    private string $username;
13
    private string $email;
14
    private string $password;
15
    private array $roles;
16
17
    public function __construct(
18
        UserUuid $uuid,
19
        NameField $username,
20
        EmailField $email,
21
        string $password,
22
        array $roles = []
23
    ) {
24
        $this->uuid = $uuid->toString();
25
        $this->username = $username->getValue();
26
        $this->email = $email->getValue();
27
        $this->password = $password;
28
        $this->roles = $roles;
29
    }
30
31
    public static function create(
32
        UserUuid $uuid,
33
        NameField $username,
34
        EmailField $email,
35
        string $password,
36
        array $roles = []
37
    ): self {
38
        return new self($uuid, $username, $email, $password, $roles);
39
    }
40
41
    public function uuid(): string
42
    {
43
        return $this->uuid;
44
    }
45
46
    public function username(): string
47
    {
48
        return $this->username;
49
    }
50
51
    public function renameUser(NameField $username): self
52
    {
53
        $this->username = $username->getValue();
54
55
        return $this;
56
    }
57
58
    public function email(): string
59
    {
60
        return $this->email;
61
    }
62
63
    public function changeEmail(EmailField $email): self
64
    {
65
        $this->email = $email->getValue();
66
67
        return $this;
68
    }
69
70
    public function password(): string
71
    {
72
        return $this->password;
73
    }
74
75
    public function changePassword(string $password): self
76
    {
77
        $this->password = $password;
78
79
        return $this;
80
    }
81
82
    public function roles(): array
83
    {
84
        return $this->roles;
85
    }
86
87
    public function assignRoles(array $roles): self
88
    {
89
        $this->roles = $roles;
90
91
        return $this;
92
    }
93
}
94