Passed
Push — master ( 2161fa...ca8612 )
by Marcel
09:08
created

User::getIdpId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Entity;
4
5
use Serializable;
6
use Stringable;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Ramsey\Uuid\Uuid;
11
use Ramsey\Uuid\UuidInterface;
12
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
13
use Symfony\Component\Security\Core\User\UserInterface;
14
use Symfony\Component\Validator\Constraints as Assert;
15
16
/**
17
 * @ORM\Entity()
18
 */
19
#[UniqueEntity(fields: ['username'])]
20
class User implements UserInterface, Stringable {
21
22
    use IdTrait;
23
    use UuidTrait;
24
25
    /**
26
     * @ORM\Column(type="uuid")
27
     */
28
    private ?UuidInterface $idpId = null;
29
30
    /**
31
     * @ORM\Column(type="string", unique=true)
32
     */
33
    private ?string $username = null;
34
35
    /**
36
     * @ORM\Column(type="string", nullable=true)
37
     */
38
    #[Assert\NotBlank(allowNull: true)]
39
    private ?string $firstname = null;
40
41
    /**
42
     * @ORM\Column(type="string", nullable=true)
43
     */
44
    #[Assert\NotBlank(allowNull: true)]
45
    private ?string $lastname = null;
46
47
    /**
48
     * @ORM\Column(type="string", nullable=true)
49
     */
50
    #[Assert\Email]
51
    #[Assert\NotBlank(allowNull: true)]
52
    private ?string $email = null;
53
54
    /**
55
     * @ORM\ManyToOne(targetEntity="Teacher")
56
     * @ORM\JoinColumn(onDelete="SET NULL")
57
     */
58
    private ?Teacher $teacher = null;
59
60
    /**
61
     * @ORM\ManyToMany(targetEntity="Student")
62
     * @ORM\JoinTable(name="user_students",
63
     *     joinColumns={@ORM\JoinColumn(onDelete="CASCADE")},
64
     *     inverseJoinColumns={@ORM\JoinColumn(onDelete="CASCADE")}
65
     * )
66
     * @var Collection<Student>
67
     */
68
    private $students;
69
70
    /**
71
     * @ORM\Column(type="json")
72
     * @var string[]
73
     */
74
    private array $roles = ['ROLE_USER'];
75
76
    /**
77
     * @ORM\Column(type="user_type")
78
     */
79
    private ?UserType $userType = null;
80
81
    /**
82
     * @ORM\ManyToMany(targetEntity="Message")
83
     * @ORM\JoinTable(name="user_dismissed_messages",
84
     *     joinColumns={@ORM\JoinColumn(onDelete="CASCADE")},
85
     *     inverseJoinColumns={@ORM\JoinColumn(onDelete="CASCADE")}
86
     * )
87
     * @var ArrayCollection<Message>
88
     */
89
    private $dismissedMessages;
90
91
    /**
92
     * @ORM\Column(type="boolean")
93
     */
94
    private bool $isSubstitutionNotificationsEnabled = false;
95
96
    /**
97
     * @ORM\Column(type="boolean")
98
     */
99
    private bool $isExamNotificationsEnabled = false;
100
101
    /**
102
     * @ORM\Column(type="boolean")
103
     */
104
    private bool $isMessageNotificationsEnabled = false;
105
106
    /**
107
     * @ORM\Column(type="boolean")
108
     */
109
    private bool $isEmailNotificationsEnabled = false;
110
111
    /**
112
     * @ORM\Column(type="json")
113
     * @var string[]
114
     */
115
    private array $data = [ ];
116
117
    public function __construct() {
118
        $this->uuid = Uuid::uuid4();
119
120
        $this->students = new ArrayCollection();
121
        $this->dismissedMessages = new ArrayCollection();
122
    }
123
124
    public function getIdpId(): ?UuidInterface {
125
        return $this->idpId;
126 28
    }
127 28
128
    public function setIdpId(UuidInterface $uuid): User {
129 28
        $this->idpId = $uuid;
130 28
        return $this;
131 28
    }
132
133
    public function getId(): ?int {
134
        return $this->id;
135
    }
136
137
    public function getFirstname(): ?string {
138
        return $this->firstname;
139
    }
140
141
    public function setFirstname(?string $firstname): User {
142
        $this->firstname = $firstname;
143
        return $this;
144 10
    }
145 10
146 10
    public function getLastname(): ?string {
147
        return $this->lastname;
148
    }
149
150
    public function setLastname(?string $lastname): User {
151
        $this->lastname = $lastname;
152 12
        return $this;
153 12
    }
154
155
    public function getEmail(): ?string {
156
        return $this->email;
157
    }
158
159 7
    public function setEmail(?string $email): User {
160 7
        $this->email = $email;
161
        return $this;
162
    }
163
164
    public function getTeacher(): ?Teacher {
165
        return $this->teacher;
166
    }
167 7
168 7
    public function setTeacher(?Teacher $teacher): User {
169 7
        $this->teacher = $teacher;
170
        return $this;
171
    }
172
173
    public function getUserType(): UserType {
174
        return $this->userType;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->userType could return the type null which is incompatible with the type-hinted return App\Entity\UserType. Consider adding an additional type-check to rule them out.
Loading history...
175 7
    }
176 7
177
    public function setUserType(UserType $userType): User {
178
        $this->userType = $userType;
179
        return $this;
180
    }
181
182
    /**
183 7
     * @param string[] $roles
184 7
     */
185 7
    public function setRoles(array $roles) {
186
        $this->roles = $roles;
187
    }
188
189
    /**
190
     * @return string[]
191 9
     */
192 9
    public function getRoles(): array {
193
        return $this->roles;
194
    }
195
196
    public function setUsername(string $username): User {
197
        $this->username = $username;
198
        return $this;
199 19
    }
200 19
201 19
    public function getUsername(): string {
202
        return $this->username;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->username could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
203
    }
204
205
    public function addDismissedMessage(Message $message) {
206
        $this->dismissedMessages->add($message);
207 9
    }
208 9
209
    public function removeDismissedMessage(Message $message) {
210
        $this->dismissedMessages->removeElement($message);
211
    }
212
213
    /**
214
     * @return Collection<Message>
215 4
     */
216 4
    public function getDismissedMessages(): Collection {
217 4
        return $this->dismissedMessages;
218
    }
219
220
    public function addStudent(Student $student) {
221
        $this->students->add($student);
222
    }
223 21
224 21
    public function removeStudent(Student $student) {
225
        $this->students->removeElement($student);
226
    }
227
228
    /**
229
     * @return Collection<Student>
230
     */
231 27
    public function getStudents(): Collection {
232 27
        return $this->students;
233 27
    }
234
235
    public function isSubstitutionNotificationsEnabled(): bool {
236
        return $this->isSubstitutionNotificationsEnabled;
237
    }
238
239 16
    public function setIsSubstitutionNotificationsEnabled(bool $isSubstitutionNotificationsEnabled): User {
240 16
        $this->isSubstitutionNotificationsEnabled = $isSubstitutionNotificationsEnabled;
241 16
        return $this;
242
    }
243
244
    public function isExamNotificationsEnabled(): bool {
245
        return $this->isExamNotificationsEnabled;
246 16
    }
247 16
248
    public function setIsExamNotificationsEnabled(bool $isExamNotificationsEnabled): User {
249
        $this->isExamNotificationsEnabled = $isExamNotificationsEnabled;
250
        return $this;
251
    }
252
253
    public function isMessageNotificationsEnabled(): bool {
254 16
        return $this->isMessageNotificationsEnabled;
255 16
    }
256 16
257
    public function setIsMessageNotificationsEnabled(bool $isMessageNotificationsEnabled): User {
258
        $this->isMessageNotificationsEnabled = $isMessageNotificationsEnabled;
259
        return $this;
260
    }
261
262 17
    public function isEmailNotificationsEnabled(): bool {
263 17
        return $this->isEmailNotificationsEnabled;
264
    }
265
266 1
    public function setIsEmailNotificationsEnabled(bool $isEmailNotificationsEnabled): User {
267 1
        $this->isEmailNotificationsEnabled = $isEmailNotificationsEnabled;
268 1
        return $this;
269
    }
270 1
271 1
    public function getData(string $key, $default = null) {
272 1
        return $this->data[$key] ?? $default;
273
    }
274
275
    public function setData(string $key, $data): void {
276
        $this->data[$key] = $data;
277 1
    }
278 1
279
    /**
280
     * @inheritDoc
281 16
     */
282 16
    public function getPassword(): ?string {
283 16
        return '';
284
    }
285
286
    /**
287
     * @inheritDoc
288
     */
289
    public function getSalt(): ?string {
290
        return null;
291
    }
292 15
293 15
    /**
294
     * @inheritDoc
295
     */
296
    public function eraseCredentials() { }
297
298
    public function getUserIdentifier(): string {
299
        return $this->getUsername();
300
    }
301
302
    public function __serialize(): array {
303
        return [
304
            'id' => $this->getId(),
305
            'username' => $this->getUsername()
306
        ];
307
    }
308
309
    public function __unserialize(array $serialized) {
310
        $this->id = $serialized['id'];
311
        $this->username = $serialized['username'];
312
    }
313
314
    public function __toString(): string {
315
        return sprintf('%s, %s (%s)', $this->getLastname(), $this->getFirstname(), $this->getUsername());
316
    }
317
}