Passed
Pull Request — develop (#130)
by Laurent
02:51 queued 01:23
created

User   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A assignRoles() 0 5 1
A changeEmail() 0 5 1
A email() 0 3 1
A renameUser() 0 5 1
A __construct() 0 12 1
A create() 0 8 1
A uuid() 0 3 1
A changePassword() 0 5 1
A password() 0 3 1
A roles() 0 7 2
A username() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Domain\User\Model;
15
16
use Administration\Domain\User\Model\VO\UserUuid;
17
use Core\Domain\Common\Model\VO\EmailField;
18
use Core\Domain\Common\Model\VO\NameField;
19
use Core\Domain\Protocol\Common\UuidProtocol;
20
21
class User
22
{
23
    protected string $uuid;
24
    protected string $username;
25
    protected string $email;
26
    protected string $password;
27
    protected array $roles;
28
29
    public function __construct(
30
        UserUuid $uuid,
31
        NameField $username,
32
        EmailField $email,
33
        string $password,
34
        array $roles = []
35
    ) {
36
        $this->uuid = $uuid->toString();
37
        $this->username = $username->getValue();
38
        $this->email = $email->getValue();
39
        $this->password = $password;
40
        $this->roles = $roles;
41
    }
42
43
    public static function create(
44
        UserUuid $uuid,
45
        NameField $username,
46
        EmailField $email,
47
        string $password,
48
        array $roles = []
49
    ): self {
50
        return new self($uuid, $username, $email, $password, $roles);
51
    }
52
53
    final public function uuid(): UuidProtocol
54
    {
55
        return UserUuid::fromString($this->uuid);
56
    }
57
58
    final public function username(): string
59
    {
60
        return $this->username;
61
    }
62
63
    final public function renameUser(NameField $username): self
64
    {
65
        $this->username = $username->getValue();
66
67
        return $this;
68
    }
69
70
    final public function email(): EmailField
71
    {
72
        return new EmailField($this->email);
73
    }
74
75
    final public function changeEmail(EmailField $email): self
76
    {
77
        $this->email = $email->getValue();
78
79
        return $this;
80
    }
81
82
    final public function password(): string
83
    {
84
        return $this->password;
85
    }
86
87
    final public function changePassword(string $password): self
88
    {
89
        $this->password = $password;
90
91
        return $this;
92
    }
93
94
    final public function roles(): array
95
    {
96
        if ([] === $this->roles) {
97
            $this->roles = ['ROLE_USER'];
98
        }
99
100
        return $this->roles;
101
    }
102
103
    final public function assignRoles(array $roles): self
104
    {
105
        $this->roles = $roles;
106
107
        return $this;
108
    }
109
}
110