Passed
Push — develop ( e1f02f...e3219b )
by Laurent
01:59
created

User::getPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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 User\Infrastructure\Doctrine\Entity;
15
16
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Symfony\Component\Security\Core\User\UserInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\User\UserInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use User\Domain\Model\User as UserModel;
19
20
/**
21
 * @ORM\Entity(repositoryClass="User\Infrastructure\Doctrine\Repository\UserRepository")
22
 * @ORM\Table(name="user")
23
 */
24
class User implements UserInterface
25
{
26
    /**
27
     * @ORM\Id
28
     * @ORM\Column(type="guid")
29
     * @ORM\GeneratedValue(strategy="NONE")
30
     */
31
    private string $uuid;
32
33
    /**
34
     * @ORM\Column(type="string", length=150, nullable=false)
35
     */
36
    private string $username;
37
38
    /**
39
     * @ORM\Column(type="string", length=255, nullable=false)
40
     */
41
    private string $email;
42
43
    /**
44
     * @ORM\Column(type="string", length=120, nullable=false)
45
     */
46
    private string $password;
47
48
    /**
49
     * @ORM\Column(type="array", nullable=false)
50
     */
51
    private array $roles;
52
53
    public function __construct(string $uuid, string $username, string $email, string $password, array $roles)
54
    {
55
        $this->uuid = $uuid;
56
        $this->username = $username;
57
        $this->email = $email;
58
        $this->password = $password;
59
        $this->roles = $roles;
60
    }
61
62
    public static function fromModel(UserModel $user): self
63
    {
64
        return new self(
65
            $user->uuid()->__toString(),
66
            $user->username()->getValue(),
67
            $user->email()->getValue(),
68
            $user->password()->value(),
69
            $user->roles()
70
        );
71
    }
72
73
    public function update(UserModel $userModel): self
74
    {
75
        $this->username = $userModel->username()->getValue();
76
        $this->email = $userModel->email()->getValue();
77
        $this->password = $userModel->password()->value();
78
        $this->roles = $userModel->roles();
79
80
        return $this;
81
    }
82
83
    public function getUuid(): string
84
    {
85
        return $this->uuid;
86
    }
87
88
    public function getEmail(): string
89
    {
90
        return $this->email;
91
    }
92
93
    public function getRoles(): array
94
    {
95
        if ([] === $this->roles) {
96
            $this->roles = ['ROLE_USER'];
97
        }
98
99
        return \array_unique($this->roles);
100
    }
101
102
    public function getPassword(): string
103
    {
104
        return $this->password;
105
    }
106
107
    public function getSalt(): ?string
108
    {
109
        return null;
110
    }
111
112
    public function getUsername(): string
113
    {
114
        return $this->username;
115
    }
116
117
    public function eraseCredentials(): void
118
    {
119
        // TODO: Implement eraseCredentials() method.
120
    }
121
122
    /**
123
     * @see AuthenticationSuccessResponseListener::onAuthenticationSuccessResponse
124
     */
125
    public function getProfileInfos(): array
126
    {
127
        return [
128
            'uuid' => $this->getUuid(),
129
            'username' => $this->getUsername(),
130
            'email' => $this->getEmail(),
131
        ];
132
    }
133
}
134