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 ( 816dcd...da4808 )
by Luis Ramón
02:55
created

User::getFullDisplayName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
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\UserInterface;
28
use Symfony\Component\Validator\Constraints as Assert;
29
use Symfony\Component\Validator\Context\ExecutionContextInterface;
30
31
/**
32
 * @ORM\Entity(repositoryClass="UserRepository")
33
 * @UniqueEntity("loginUsername")
34
 */
35
class User extends Person implements UserInterface, \Serializable
36
{
37
    /**
38
     * @ORM\Id
39
     * @ORM\Column(type="integer")
40
     * @ORM\GeneratedValue
41
     * @var int
42
     */
43
    protected $id;
44
45
    /**
46
     * @ORM\Column(type="string", nullable=true)
47
     * @Assert\Regex(pattern="/[@ ]{1,}/", match=false, message="login_username.invalid_chars", htmlPattern=false)
48
     * @Assert\Length(min=5)
49
     * @var string
50
     */
51
    protected $loginUsername;
52
53
    /**
54
     * @ORM\Column(type="string", nullable=true)
55
     * @Assert\Length(min=7)
56
     * @var string
57
     */
58
    protected $password;
59
60
    /**
61
     * @ORM\Column(type="string", nullable=true)
62
     * @var string
63
     */
64
    protected $token;
65
66
    /**
67
     * @ORM\Column(type="datetime", nullable=true)
68
     * @var \DateTime
69
     */
70
    protected $tokenValidity;
71
72
    /**
73
     * @ORM\Column(type="boolean")
74
     * @var bool
75
     */
76
    protected $enabled;
77
78
    /**
79
     * @ORM\Column(type="boolean")
80
     * @var bool
81
     */
82
    protected $globalAdministrator;
83
84
    /**
85
     * @ORM\Column(type="datetime", nullable=true)
86
     * @var \DateTime
87
     */
88
    protected $lastLogin;
89
90
    /**
91
     * @ORM\ManyToOne(targetEntity="Group", inversedBy="students")
92
     *
93
     * @var Group
94
     */
95
    protected $studentGroup;
96
97
    /**
98
     * @ORM\ManyToMany(targetEntity="Group", mappedBy="tutors")
99
     * @ORM\JoinTable(name="tutorized_groups")
100
     *
101
     * @var Collection
102
     */
103
    protected $tutorizedGroups;
104
105
    /**
106
     * @ORM\OneToMany(targetEntity="Department", mappedBy="head")
107
     *
108
     * @var Collection
109
     */
110
    protected $directs;
111
112
    /**
113
     * Constructor
114
     */
115
    public function __construct()
116
    {
117
        parent::__construct();
118
119
        $this->tutorizedGroups = new \Doctrine\Common\Collections\ArrayCollection();
120
    }
121
122
    /**
123
     * Returns the person's display name
124
     *
125
     * @return string
126
     */
127
    public function getFullDisplayName()
128
    {
129
        $displayName = (string) $this;
130
131
        if (null !== $this->getStudentGroup()) {
132
            $displayName .= ' (' . (string) $this->getStudentGroup() . ')';
133
        }
134
        
135
        return $displayName;
136
    }
137
138
    /**
139
     * Get id
140
     *
141
     * @return integer
142
     */
143
    public function getId()
144
    {
145
        return $this->id;
146
    }
147
148
    /**
149
     * Get login username
150
     *
151
     * @return string
152
     */
153
    public function getLoginUsername()
154
    {
155
        return $this->loginUsername;
156
    }
157
158
    /**
159
     * Set login username
160
     *
161
     * @param string $loginUsername
162
     *
163
     * @return User
164
     */
165
    public function setLoginUsername($loginUsername)
166
    {
167
        $this->loginUsername = $loginUsername;
168
169
        return $this;
170
    }
171
172
    /**
173
     * Get password
174
     *
175
     * @return string
176
     */
177
    public function getPassword()
178
    {
179
        return $this->password;
180
    }
181
182
    /**
183
     * Set password
184
     *
185
     * @param string $password
186
     *
187
     * @return User
188
     */
189
    public function setPassword($password)
190
    {
191
        $this->password = $password;
192
193
        return $this;
194
    }
195
196
    /**
197
     * Get token
198
     *
199
     * @return string
200
     */
201
    public function getToken()
202
    {
203
        return $this->token;
204
    }
205
206
    /**
207
     * Set token
208
     *
209
     * @param string $token
210
     *
211
     * @return User
212
     */
213
    public function setToken($token)
214
    {
215
        $this->token = $token;
216
217
        return $this;
218
    }
219
220
    /**
221
     * Get tokenValidity
222
     *
223
     * @return \DateTime
224
     */
225
    public function getTokenValidity()
226
    {
227
        return $this->tokenValidity;
228
    }
229
230
    /**
231
     * Set tokenValidity
232
     *
233
     * @param \DateTime $tokenValidity
234
     *
235
     * @return User
236
     */
237
    public function setTokenValidity($tokenValidity)
238
    {
239
        $this->tokenValidity = $tokenValidity;
240
241
        return $this;
242
    }
243
244
    /**
245
     * Get enabled
246
     *
247
     * @return boolean
248
     */
249
    public function isEnabled()
250
    {
251
        return $this->enabled;
252
    }
253
254
    /**
255
     * Set enabled
256
     *
257
     * @param boolean $enabled
258
     *
259
     * @return User
260
     */
261
    public function setEnabled($enabled)
262
    {
263
        $this->enabled = $enabled;
264
265
        return $this;
266
    }
267
268
    /**
269
     * Get globalAdministrator
270
     *
271
     * @return boolean
272
     */
273
    public function isGlobalAdministrator()
274
    {
275
        return $this->globalAdministrator;
276
    }
277
278
    /**
279
     * Set globalAdministrator
280
     *
281
     * @param boolean $globalAdministrator
282
     *
283
     * @return User
284
     */
285
    public function setGlobalAdministrator($globalAdministrator)
286
    {
287
        $this->globalAdministrator = $globalAdministrator;
288
289
        return $this;
290
    }
291
292
    /**
293
     * String representation of object
294
     * @link http://php.net/manual/en/serializable.serialize.php
295
     * @return string the string representation of the object or null
296
     * @since 5.1.0
297
     */
298
    public function serialize()
299
    {
300
        return serialize(array(
301
            $this->id,
302
            $this->email,
303
            $this->loginUsername,
304
            $this->password
305
        ));
306
    }
307
308
    /**
309
     * Constructs the object
310
     * @link http://php.net/manual/en/serializable.unserialize.php
311
     * @param string $serialized <p>
312
     * The string representation of the object.
313
     * </p>
314
     * @return void
315
     * @since 5.1.0
316
     */
317
    public function unserialize($serialized)
318
    {
319
        list (
320
            $this->id,
321
            $this->email,
322
            $this->loginUsername,
323
            $this->password
324
        ) = unserialize($serialized);
325
    }
326
327
    /**
328
     * Returns the salt that was originally used to encode the password.
329
     *
330
     * This can return null if the password was not encoded using a salt.
331
     *
332
     * @return string|null The salt
333
     */
334
    public function getSalt()
335
    {
336
        return null;
337
    }
338
339
    /**
340
     * Removes sensitive data from the user.
341
     *
342
     * This is important if, at any given point, sensitive information like
343
     * the plain-text password is stored on this object.
344
     */
345
    public function eraseCredentials()
346
    {
347
    }
348
349
    /**
350
     * Returns the roles granted to the user.
351
     *
352
     * @return Role[] The user roles
353
     */
354
    public function getRoles()
355
    {
356
        // Always return ROLE_USER
357
        $roles = [new Role('ROLE_USER')];
358
359
        if ($this->isGlobalAdministrator()) {
360
            $roles[] = new Role('ROLE_ADMIN');
361
        }
362
363
        return $roles;
364
    }
365
366
    /**
367
     * Set lastLogin
368
     *
369
     * @param \DateTime $lastLogin
370
     *
371
     * @return User
372
     */
373
    public function setLastLogin($lastLogin)
374
    {
375
        $this->lastLogin = $lastLogin;
376
377
        return $this;
378
    }
379
380
    /**
381
     * Get lastLogin
382
     *
383
     * @return \DateTime
384
     */
385
    public function getLastLogin()
386
    {
387
        return $this->lastLogin;
388
    }
389
390
    /**
391
     * Set group
392
     *
393
     * @param Group $group
394
     *
395
     * @return User
396
     */
397
    public function setStudentGroup(Group $group = null)
398
    {
399
        $this->studentGroup = $group;
400
401
        return $this;
402
    }
403
404
    /**
405
     * Get group
406
     *
407
     * @return Group
408
     */
409
    public function getStudentGroup()
410
    {
411
        return $this->studentGroup;
412
    }
413
414
    /**
415
     * Add tutorizedGroup
416
     *
417
     * @param Group $tutorizedGroup
418
     *
419
     * @return User
420
     */
421 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...
422
    {
423
        if (false === $this->tutorizedGroups->contains($tutorizedGroup)) {
424
            $this->tutorizedGroups[] = $tutorizedGroup;
425
            $tutorizedGroup->addTutor($this);
426
        }
427
428
        return $this;
429
    }
430
431
    /**
432
     * Remove tutorizedGroup
433
     *
434
     * @param Group $tutorizedGroup
435
     */
436 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...
437
    {
438
        if (true === $this->tutorizedGroups->contains($tutorizedGroup)) {
439
            $this->tutorizedGroups->removeElement($tutorizedGroup);
440
            $tutorizedGroup->removeTutor($this);
441
        }
442
    }
443
444
    /**
445
     * Get tutorizedGroups
446
     *
447
     * @return Collection
448
     */
449
    public function getTutorizedGroups()
450
    {
451
        return $this->tutorizedGroups;
452
    }
453
454
    /**
455
     * Add direct
456
     *
457
     * @param Department $direct
458
     *
459
     * @return User
460
     */
461
    public function addDirect(Department $direct)
462
    {
463
        $this->directs[] = $direct;
464
465
        return $this;
466
    }
467
468
    /**
469
     * Remove direct
470
     *
471
     * @param Department $direct
472
     */
473
    public function removeDirect(Department $direct)
474
    {
475
        $this->directs->removeElement($direct);
476
    }
477
478
    /**
479
     * Get directs
480
     *
481
     * @return Collection
482
     */
483
    public function getDirects()
484
    {
485
        return $this->directs;
486
    }
487
488
    /**
489
     * @Assert\Callback
490
     */
491
    public function validate(ExecutionContextInterface $context)
492
    {
493
        // comprobar si se ha especificado al menos el nombre de usuario o el correo electrónico
494
        if (!$this->getLoginUsername() && !$this->getEmail()) {
495
            $context->buildViolation('user.id.not_found')
496
                ->atPath('loginUsername')
497
                ->addViolation();
498
            $context->buildViolation('user.id.not_found')
499
                ->atPath('email')
500
                ->addViolation();
501
        }
502
    }
503
504
    /**
505
     * Returns the username used to authenticate the user.
506
     *
507
     * @return string The username
508
     */
509
    public function getUsername()
510
    {
511
        return $this->getLoginUsername() ?: $this->getEmail();
512
    }
513
}
514