Passed
Push — develop ( 6aee1f...577144 )
by Laurent
01:44
created

User   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
dl 0
loc 118
rs 10
c 1
b 0
f 0
wmc 14

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setUuid() 0 5 1
A getUuid() 0 3 1
A getPassword() 0 3 1
A getEmail() 0 3 1
A setEmail() 0 5 1
A getRoles() 0 7 2
A __construct() 0 7 1
A getSalt() 0 3 1
A getUsername() 0 3 1
A eraseCredentials() 0 2 1
A getProfileInfos() 0 6 1
A setPassword() 0 5 1
A fromModel() 0 8 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 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 getPassword(): string
107
    {
108
        return $this->password;
109
    }
110
111
    public function setPassword(string $password): self
112
    {
113
        $this->password = $password;
114
115
        return $this;
116
    }
117
118
    public function getSalt(): ?string
119
    {
120
        return null;
121
    }
122
123
    public function getUsername(): string
124
    {
125
        return $this->username;
126
    }
127
128
    public function eraseCredentials(): void
129
    {
130
        // TODO: Implement eraseCredentials() method.
131
    }
132
133
    /**
134
     * @see AuthenticationSuccessResponseListener::onAuthenticationSuccessResponse
135
     */
136
    public function getProfileInfos(): array
137
    {
138
        return [
139
            'uuid' => $this->getUuid(),
140
            'username' => $this->getUsername(),
141
            'email' => $this->getEmail(),
142
        ];
143
    }
144
}
145