Passed
Push — main ( 79e4f1...ed1bb6 )
by Slawomir
04:28
created

User   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 130
ccs 24
cts 28
cp 0.8571
rs 10
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getEmail() 0 3 1
A getRoles() 0 7 1
A getPassword() 0 3 1
A getSalt() 0 3 1
A getUserIdentifier() 0 3 1
A setEmail() 0 5 1
A setPassword() 0 5 1
A setRoles() 0 5 1
A setVersion() 0 3 1
A getId() 0 3 1
A eraseCredentials() 0 2 1
A getVersion() 0 3 1
1
<?php
2
3
namespace App\Modules\Security\Persistence\Doctrine\Entity;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
8
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
use Symfony\Component\Uid\Ulid;
11
12
#[ORM\Entity]
13
#[ORM\Table(name: "USERS")]
14
class User implements UserInterface, PasswordAuthenticatedUserInterface
15
{
16 1
17
    /**
18
     * @var Ulid
19
     */
20
    #[ORM\Id]
21
    #[ORM\GeneratedValue(strategy: "CUSTOM")]
22
    #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
23
    #[ORM\Column(type: "ulid", unique: true)]
24
    private Ulid $id;
25
26
    /**
27
     * @var string
28
     */
29
    #[ORM\Column(type: "string", length: 180, unique: true)]
30
    private string $email;
31
32
    /**
33
     * @var array<string>
34
     */
35
    #[ORM\Column(type: "json")]
36
    private array $roles = [];
37
38
    /**
39
     * @var string The hashed password
40
     */
41
    #[ORM\Column(type: "string")]
42
    private string $password;
43
44
    #[ORM\Version]
45
    #[ORM\Column(type: "integer")]
46
    private $version;
47
48
49
    public function getId(): ?Ulid
50
    {
51
        return $this->id;
52
    }
53
54 3
    public function getEmail(): ?string
55
    {
56 3
        return $this->email;
57
    }
58
59 3
    public function setEmail(string $email): self
60
    {
61 3
        $this->email = $email;
62
63
        return $this;
64 1
    }
65
66 1
    /**
67
     * The public representation of the user (e.g. a username, an email address, etc.)
68 1
     *
69
     * @see UserInterface
70
     */
71
    public function getUserIdentifier(): string
72
    {
73
        return (string)$this->email;
74
    }
75
76 3
    /**
77
     * @see UserInterface
78 3
     */
79
    public function getRoles(): array
80
    {
81
        $roles = $this->roles;
82
        // guarantee every user at least has ROLE_USER
83
        $roles[] = 'ROLE_USER';
84 3
85
        return array_unique($roles);
86 3
    }
87
88 3
    public function setRoles(array $roles): self
89
    {
90 3
        $this->roles = $roles;
91
92
        return $this;
93 1
    }
94
95 1
    /**
96
     * @see PasswordAuthenticatedUserInterface
97 1
     */
98
    public function getPassword(): string
99
    {
100
        return $this->password;
101
    }
102
103 3
    public function setPassword(string $password): self
104
    {
105 3
        $this->password = $password;
106
107
        return $this;
108 1
    }
109
110 1
    /**
111
     * Returning a salt is only needed, if you are not using a modern
112 1
     * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
113
     *
114
     * @see UserInterface
115
     */
116
    public function getSalt(): ?string
117
    {
118
        return null;
119
    }
120
121
    /**
122
     * @see UserInterface
123
     */
124
    public function eraseCredentials()
125
    {
126
    }
127
128
    /**
129 3
     * @return mixed
130
     */
131
    public function getVersion()
132
    {
133 3
        return $this->version;
134
    }
135
136
    /**
137
     * @param mixed $version
138
     */
139
    public function setVersion($version): void
140
    {
141
        $this->version = $version;
142
    }
143
}