Passed
Pull Request — orm-management (#169)
by
unknown
03:15 queued 01:42
created

User::fromModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 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 Core\Infrastructure\Persistence\DoctrineOrm\Entities;
15
16
use Administration\Domain\User\Model\User as UserModel;
17
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...
18
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...
19
20
/**
21
 * @ORM\Entity(repositoryClass="Administration\Infrastructure\Persistence\DoctrineOrm\Repositories\DoctrineUserRepository")
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(),
67
            $user->email()->getValue(),
68
            $user->password(),
69
            $user->roles()
70
        );
71
    }
72
73
    public function getUuid(): string
74
    {
75
        return $this->uuid;
76
    }
77
78
    public function setUuid(string $uuid): self
79
    {
80
        $this->uuid = $uuid;
81
82
        return $this;
83
    }
84
85
    public function getEmail(): string
86
    {
87
        return $this->email;
88
    }
89
90
    public function setEmail(string $email): self
91
    {
92
        $this->email = $email;
93
94
        return $this;
95
    }
96
97
    public function getRoles(): array
98
    {
99
        if ([] === $this->roles) {
100
            $this->roles = ['ROLE_USER'];
101
        }
102
103
        return \array_unique($this->roles);
104
    }
105
106
    public function setRoles(array $roles): self
107
    {
108
        $this->roles = $roles;
109
110
        return $this;
111
    }
112
113
    public function getPassword(): string
114
    {
115
        return $this->password;
116
    }
117
118
    public function setPassword(string $password): self
119
    {
120
        $this->password = $password;
121
122
        return $this;
123
    }
124
125
    public function getSalt(): ?string
126
    {
127
        return null;
128
    }
129
130
    public function getUsername(): string
131
    {
132
        return $this->username;
133
    }
134
135
    public function setUsername(string $username): self
136
    {
137
        $this->username = $username;
138
139
        return $this;
140
    }
141
142
    public function eraseCredentials(): void
143
    {
144
        // TODO: Implement eraseCredentials() method.
145
    }
146
147
    /**
148
     * @see AuthenticationSuccessResponseListener::onAuthenticationSuccessResponse
149
     */
150
    public function getProfileInfos(): array
151
    {
152
        return [
153
            'uuid' => $this->getUuid(),
154
            'username' => $this->getUsername(),
155
            'email' => $this->getEmail(),
156
        ];
157
    }
158
}
159