Passed
Push — main ( 65c0e3...2d780d )
by Slawomir
04:29
created

User::eraseCredentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
ccs 0
cts 0
cp 0
crap 2
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
    #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserPostHeader::class)]
49
    private Collection $posts;
50
51
52
    public function getId(): ?Ulid
53
    {
54 3
        return $this->id;
55
    }
56 3
57
    public function getEmail(): ?string
58
    {
59 3
        return $this->email;
60
    }
61 3
62
    public function setEmail(string $email): self
63
    {
64 1
        $this->email = $email;
65
66 1
        return $this;
67
    }
68 1
69
    /**
70
     * The public representation of the user (e.g. a username, an email address, etc.)
71
     *
72
     * @see UserInterface
73
     */
74
    public function getUserIdentifier(): string
75
    {
76 3
        return (string)$this->email;
77
    }
78 3
79
    /**
80
     * @see UserInterface
81
     */
82
    public function getRoles(): array
83
    {
84 3
        $roles = $this->roles;
85
        // guarantee every user at least has ROLE_USER
86 3
        $roles[] = 'ROLE_USER';
87
88 3
        return array_unique($roles);
89
    }
90 3
91
    public function setRoles(array $roles): self
92
    {
93 1
        $this->roles = $roles;
94
95 1
        return $this;
96
    }
97 1
98
    /**
99
     * @see PasswordAuthenticatedUserInterface
100
     */
101
    public function getPassword(): string
102
    {
103 3
        return $this->password;
104
    }
105 3
106
    public function setPassword(string $password): self
107
    {
108 1
        $this->password = $password;
109
110 1
        return $this;
111
    }
112 1
113
    /**
114
     * Returning a salt is only needed, if you are not using a modern
115
     * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
116
     *
117
     * @see UserInterface
118
     */
119
    public function getSalt(): ?string
120
    {
121
        return null;
122
    }
123
124
    /**
125
     * @see UserInterface
126
     */
127
    public function eraseCredentials()
128
    {
129 3
        // If you store any temporary, sensitive data on the user, clear it here
130
        // $this->plainPassword = null;
131
    }
132
133 3
    /**
134
     * @return mixed
135
     */
136
    public function getVersion()
137
    {
138
        return $this->version;
139
    }
140
141
    /**
142
     * @param mixed $version
143
     */
144
    public function setVersion($version): void
145
    {
146
        $this->version = $version;
147
    }
148
149
    /**
150
     * @return Collection
151
     */
152
    public function getPosts(): Collection
153
    {
154
        return $this->posts;
155
    }
156
157
    /**
158
     * @param Collection $posts
159
     */
160
    public function setPosts(Collection $posts): void
161
    {
162
        $this->posts = $posts;
163
    }
164
165
166
}