GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — user-entity ( 60964d...6b9ec2 )
by Luis Ramón
02:42
created

User::getRoles()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 19
rs 8.8571
cc 6
eloc 9
nc 8
nop 0
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Entity;
22
23
use Doctrine\Common\Collections\Collection;
24
use Doctrine\ORM\Mapping as ORM;
25
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
26
use Symfony\Component\Security\Core\Role\Role;
27
use Symfony\Component\Security\Core\User\EquatableInterface;
28
use Symfony\Component\Security\Core\User\UserInterface;
29
use Symfony\Component\Validator\Constraints as Assert;
30
use Symfony\Component\Validator\Context\ExecutionContextInterface;
31
32
/**
33
 * @ORM\Entity(repositoryClass="UserRepository")
34
 * @UniqueEntity("loginUsername")
35
 */
36
class User extends Person implements UserInterface, \Serializable, EquatableInterface
37
{
38
    /**
39
     * @ORM\Id
40
     * @ORM\Column(type="integer")
41
     * @ORM\GeneratedValue
42
     * @var int
43
     */
44
    protected $id;
45
46
    /**
47
     * @ORM\Column(type="string", nullable=true)
48
     * @Assert\Regex(pattern="/[@ ]{1,}/", match=false, message="login_username.invalid_chars", htmlPattern=false)
49
     * @Assert\Length(min=5)
50
     * @var string
51
     */
52
    protected $loginUsername;
53
54
    /**
55
     * @ORM\Column(type="string", nullable=true)
56
     * @Assert\Length(min=7)
57
     * @var string
58
     */
59
    protected $password;
60
61
    /**
62
     * @ORM\Column(type="string", nullable=true)
63
     * @var string
64
     */
65
    protected $token;
66
67
    /**
68
     * @ORM\Column(type="datetime", nullable=true)
69
     * @var \DateTime
70
     */
71
    protected $tokenValidity;
72
73
    /**
74
     * @ORM\Column(type="boolean")
75
     * @var bool
76
     */
77
    protected $enabled;
78
79
    /**
80
     * @ORM\Column(type="boolean")
81
     * @var bool
82
     */
83
    protected $globalAdministrator;
84
85
    /**
86
     * @ORM\Column(type="datetime", nullable=true)
87
     * @var \DateTime
88
     */
89
    protected $lastLogin;
90
91
    /**
92
     * @ORM\ManyToOne(targetEntity="Group", inversedBy="students")
93
     *
94
     * @var Group
95
     */
96
    protected $studentGroup;
97
98
    /**
99
     * @ORM\ManyToMany(targetEntity="Group", mappedBy="tutors")
100
     * @ORM\JoinTable(name="tutorized_groups")
101
     *
102
     * @var Collection
103
     */
104
    protected $tutorizedGroups;
105
106
    /**
107
     * @ORM\OneToMany(targetEntity="Department", mappedBy="head")
108
     *
109
     * @var Collection
110
     */
111
    protected $directs;
112
113
    /**
114
     * Constructor
115
     */
116
    public function __construct()
117
    {
118
        parent::__construct();
119
120
        $this->tutorizedGroups = new \Doctrine\Common\Collections\ArrayCollection();
121
        $this->directs = new \Doctrine\Common\Collections\ArrayCollection();
122
    }
123
124
    /**
125
     * Returns the person's display name
126
     *
127
     * @return string
128
     */
129
    public function getFullDisplayName()
130
    {
131
        $displayName = (string) $this;
132
133
        if (null !== $this->getStudentGroup()) {
134
            $displayName .= ' (' . (string) $this->getStudentGroup() . ')';
135
        }
136
137
        return $displayName;
138
    }
139
140
    /**
141
     * Get id
142
     *
143
     * @return integer
144
     */
145
    public function getId()
146
    {
147
        return $this->id;
148
    }
149
150
    /**
151
     * Get login username
152
     *
153
     * @return string
154
     */
155
    public function getLoginUsername()
156
    {
157
        return $this->loginUsername;
158
    }
159
160
    /**
161
     * Set login username
162
     *
163
     * @param string $loginUsername
164
     *
165
     * @return User
166
     */
167
    public function setLoginUsername($loginUsername)
168
    {
169
        $this->loginUsername = $loginUsername;
170
171
        return $this;
172
    }
173
174
    /**
175
     * Get password
176
     *
177
     * @return string
178
     */
179
    public function getPassword()
180
    {
181
        return $this->password;
182
    }
183
184
    /**
185
     * Set password
186
     *
187
     * @param string $password
188
     *
189
     * @return User
190
     */
191
    public function setPassword($password)
192
    {
193
        $this->password = $password;
194
195
        return $this;
196
    }
197
198
    /**
199
     * Get token
200
     *
201
     * @return string
202
     */
203
    public function getToken()
204
    {
205
        return $this->token;
206
    }
207
208
    /**
209
     * Set token
210
     *
211
     * @param string $token
212
     *
213
     * @return User
214
     */
215
    public function setToken($token)
216
    {
217
        $this->token = $token;
218
219
        return $this;
220
    }
221
222
    /**
223
     * Get tokenValidity
224
     *
225
     * @return \DateTime
226
     */
227
    public function getTokenValidity()
228
    {
229
        return $this->tokenValidity;
230
    }
231
232
    /**
233
     * Set tokenValidity
234
     *
235
     * @param \DateTime $tokenValidity
236
     *
237
     * @return User
238
     */
239
    public function setTokenValidity($tokenValidity)
240
    {
241
        $this->tokenValidity = $tokenValidity;
242
243
        return $this;
244
    }
245
246
    /**
247
     * Get enabled
248
     *
249
     * @return boolean
250
     */
251
    public function isEnabled()
252
    {
253
        return $this->enabled;
254
    }
255
256
    /**
257
     * Set enabled
258
     *
259
     * @param boolean $enabled
260
     *
261
     * @return User
262
     */
263
    public function setEnabled($enabled)
264
    {
265
        $this->enabled = $enabled;
266
267
        return $this;
268
    }
269
270
    /**
271
     * Get globalAdministrator
272
     *
273
     * @return boolean
274
     */
275
    public function isGlobalAdministrator()
276
    {
277
        return $this->globalAdministrator;
278
    }
279
280
    /**
281
     * Set globalAdministrator
282
     *
283
     * @param boolean $globalAdministrator
284
     *
285
     * @return User
286
     */
287
    public function setGlobalAdministrator($globalAdministrator)
288
    {
289
        $this->globalAdministrator = $globalAdministrator;
290
291
        return $this;
292
    }
293
294
    /**
295
     * String representation of object
296
     * @link http://php.net/manual/en/serializable.serialize.php
297
     * @return string the string representation of the object or null
298
     * @since 5.1.0
299
     */
300
    public function serialize()
301
    {
302
        return serialize(array(
303
            $this->id,
304
            $this->email,
305
            $this->loginUsername,
306
            $this->password
307
        ));
308
    }
309
310
    /**
311
     * Constructs the object
312
     * @link http://php.net/manual/en/serializable.unserialize.php
313
     * @param string $serialized <p>
314
     * The string representation of the object.
315
     * </p>
316
     * @return void
317
     * @since 5.1.0
318
     */
319
    public function unserialize($serialized)
320
    {
321
        list (
322
            $this->id,
323
            $this->email,
324
            $this->loginUsername,
325
            $this->password
326
        ) = unserialize($serialized);
327
    }
328
329
    /**
330
     * The equality comparison should neither be done by referential equality
331
     * nor by comparing identities (i.e. getId() === getId()).
332
     *
333
     * However, you do not need to compare every attribute, but only those that
334
     * are relevant for assessing whether re-authentication is required.
335
     *
336
     * Also implementation should consider that $user instance may implement
337
     * the extended user interface `AdvancedUserInterface`.
338
     *
339
     * @param UserInterface $user
340
     *
341
     * @return bool
342
     */
343
    public function isEqualTo(UserInterface $user)
344
    {
345
        return ($this->getRoles() === $user->getRoles());
346
    }
347
348
    /**
349
     * Returns the salt that was originally used to encode the password.
350
     *
351
     * This can return null if the password was not encoded using a salt.
352
     *
353
     * @return string|null The salt
354
     */
355
    public function getSalt()
356
    {
357
        return null;
358
    }
359
360
    /**
361
     * Removes sensitive data from the user.
362
     *
363
     * This is important if, at any given point, sensitive information like
364
     * the plain-text password is stored on this object.
365
     */
366
    public function eraseCredentials()
367
    {
368
    }
369
370
    /**
371
     * Returns the roles granted to the user.
372
     *
373
     * @return Role[] The user roles
374
     */
375
    public function getRoles()
376
    {
377
        // Always return ROLE_USER
378
        $roles = [new Role('ROLE_USER')];
379
380
        if ($this->isGlobalAdministrator()) {
381
            $roles[] = new Role('ROLE_ADMIN');
382
        }
383
384
        if ($this->tutorizedGroups && $this->tutorizedGroups->count()) {
385
            $roles[] = new Role('ROLE_GROUP_TUTOR');
386
        }
387
388
        if ($this->directs && $this->directs->count()) {
389
            $roles[] = new Role('ROLE_DEPARTMENT_HEAD');
390
        }
391
392
        return $roles;
393
    }
394
395
    /**
396
     * Set lastLogin
397
     *
398
     * @param \DateTime $lastLogin
399
     *
400
     * @return User
401
     */
402
    public function setLastLogin($lastLogin)
403
    {
404
        $this->lastLogin = $lastLogin;
405
406
        return $this;
407
    }
408
409
    /**
410
     * Get lastLogin
411
     *
412
     * @return \DateTime
413
     */
414
    public function getLastLogin()
415
    {
416
        return $this->lastLogin;
417
    }
418
419
    /**
420
     * Set group
421
     *
422
     * @param Group $group
423
     *
424
     * @return User
425
     */
426
    public function setStudentGroup(Group $group = null)
427
    {
428
        $this->studentGroup = $group;
429
430
        return $this;
431
    }
432
433
    /**
434
     * Get group
435
     *
436
     * @return Group
437
     */
438
    public function getStudentGroup()
439
    {
440
        return $this->studentGroup;
441
    }
442
443
    /**
444
     * Add tutorizedGroup
445
     *
446
     * @param Group $tutorizedGroup
447
     *
448
     * @return User
449
     */
450 View Code Duplication
    public function addTutorizedGroup(Group $tutorizedGroup)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
451
    {
452
        if (false === $this->tutorizedGroups->contains($tutorizedGroup)) {
453
            $this->tutorizedGroups[] = $tutorizedGroup;
454
            $tutorizedGroup->addTutor($this);
455
        }
456
457
        return $this;
458
    }
459
460
    /**
461
     * Remove tutorizedGroup
462
     *
463
     * @param Group $tutorizedGroup
464
     */
465 View Code Duplication
    public function removeTutorizedGroup(Group $tutorizedGroup)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
466
    {
467
        if (true === $this->tutorizedGroups->contains($tutorizedGroup)) {
468
            $this->tutorizedGroups->removeElement($tutorizedGroup);
469
            $tutorizedGroup->removeTutor($this);
470
        }
471
    }
472
473
    /**
474
     * Get tutorizedGroups
475
     *
476
     * @return Collection
477
     */
478
    public function getTutorizedGroups()
479
    {
480
        return $this->tutorizedGroups;
481
    }
482
483
    /**
484
     * Add direct
485
     *
486
     * @param Department $direct
487
     *
488
     * @return User
489
     */
490
    public function addDirect(Department $direct)
491
    {
492
        $this->directs[] = $direct;
493
494
        return $this;
495
    }
496
497
    /**
498
     * Remove direct
499
     *
500
     * @param Department $direct
501
     */
502
    public function removeDirect(Department $direct)
503
    {
504
        $this->directs->removeElement($direct);
505
    }
506
507
    /**
508
     * Get directs
509
     *
510
     * @return Collection
511
     */
512
    public function getDirects()
513
    {
514
        return $this->directs;
515
    }
516
517
    /**
518
     * @Assert\Callback
519
     */
520
    public function validate(ExecutionContextInterface $context)
521
    {
522
        // comprobar si se ha especificado al menos el nombre de usuario o el correo electrónico
523
        if (!$this->getLoginUsername() && !$this->getEmail()) {
524
            $context->buildViolation('user.id.not_found')
525
                ->atPath('loginUsername')
526
                ->addViolation();
527
            $context->buildViolation('user.id.not_found')
528
                ->atPath('email')
529
                ->addViolation();
530
        }
531
    }
532
533
    /**
534
     * Returns the username used to authenticate the user.
535
     *
536
     * @return string The username
537
     */
538
    public function getUsername()
539
    {
540
        return $this->getLoginUsername() ?: $this->getEmail();
541
    }
542
543
}
544