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
Branch user-entity (5d2483)
by Luis Ramón
03:29
created

User::getStudentGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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
     * Get id
124
     *
125
     * @return integer
126
     */
127
    public function getId()
128
    {
129
        return $this->id;
130
    }
131
132
    /**
133
     * Get login username
134
     *
135
     * @return string
136
     */
137
    public function getLoginUsername()
138
    {
139
        return $this->loginUsername;
140
    }
141
142
    /**
143
     * Set login username
144
     *
145
     * @param string $loginUsername
146
     *
147
     * @return User
148
     */
149
    public function setLoginUsername($loginUsername)
150
    {
151
        $this->loginUsername = $loginUsername;
152
153
        return $this;
154
    }
155
156
    /**
157
     * Get password
158
     *
159
     * @return string
160
     */
161
    public function getPassword()
162
    {
163
        return $this->password;
164
    }
165
166
    /**
167
     * Set password
168
     *
169
     * @param string $password
170
     *
171
     * @return User
172
     */
173
    public function setPassword($password)
174
    {
175
        $this->password = $password;
176
177
        return $this;
178
    }
179
180
    /**
181
     * Get token
182
     *
183
     * @return string
184
     */
185
    public function getToken()
186
    {
187
        return $this->token;
188
    }
189
190
    /**
191
     * Set token
192
     *
193
     * @param string $token
194
     *
195
     * @return User
196
     */
197
    public function setToken($token)
198
    {
199
        $this->token = $token;
200
201
        return $this;
202
    }
203
204
    /**
205
     * Get tokenValidity
206
     *
207
     * @return \DateTime
208
     */
209
    public function getTokenValidity()
210
    {
211
        return $this->tokenValidity;
212
    }
213
214
    /**
215
     * Set tokenValidity
216
     *
217
     * @param \DateTime $tokenValidity
218
     *
219
     * @return User
220
     */
221
    public function setTokenValidity($tokenValidity)
222
    {
223
        $this->tokenValidity = $tokenValidity;
224
225
        return $this;
226
    }
227
228
    /**
229
     * Get enabled
230
     *
231
     * @return boolean
232
     */
233
    public function isEnabled()
234
    {
235
        return $this->enabled;
236
    }
237
238
    /**
239
     * Set enabled
240
     *
241
     * @param boolean $enabled
242
     *
243
     * @return User
244
     */
245
    public function setEnabled($enabled)
246
    {
247
        $this->enabled = $enabled;
248
249
        return $this;
250
    }
251
252
    /**
253
     * Get globalAdministrator
254
     *
255
     * @return boolean
256
     */
257
    public function isGlobalAdministrator()
258
    {
259
        return $this->globalAdministrator;
260
    }
261
262
    /**
263
     * Set globalAdministrator
264
     *
265
     * @param boolean $globalAdministrator
266
     *
267
     * @return User
268
     */
269
    public function setGlobalAdministrator($globalAdministrator)
270
    {
271
        $this->globalAdministrator = $globalAdministrator;
272
273
        return $this;
274
    }
275
276
    /**
277
     * String representation of object
278
     * @link http://php.net/manual/en/serializable.serialize.php
279
     * @return string the string representation of the object or null
280
     * @since 5.1.0
281
     */
282
    public function serialize()
283
    {
284
        return serialize(array(
285
            $this->id,
286
            $this->email,
287
            $this->loginUsername,
288
            $this->password
289
        ));
290
    }
291
292
    /**
293
     * Constructs the object
294
     * @link http://php.net/manual/en/serializable.unserialize.php
295
     * @param string $serialized <p>
296
     * The string representation of the object.
297
     * </p>
298
     * @return void
299
     * @since 5.1.0
300
     */
301
    public function unserialize($serialized)
302
    {
303
        list (
304
            $this->id,
305
            $this->email,
306
            $this->loginUsername,
307
            $this->password
308
        ) = unserialize($serialized);
309
    }
310
311
    /**
312
     * Returns the salt that was originally used to encode the password.
313
     *
314
     * This can return null if the password was not encoded using a salt.
315
     *
316
     * @return string|null The salt
317
     */
318
    public function getSalt()
319
    {
320
        return null;
321
    }
322
323
    /**
324
     * Removes sensitive data from the user.
325
     *
326
     * This is important if, at any given point, sensitive information like
327
     * the plain-text password is stored on this object.
328
     */
329
    public function eraseCredentials()
330
    {
331
    }
332
333
    /**
334
     * Returns the roles granted to the user.
335
     *
336
     * @return Role[] The user roles
337
     */
338
    public function getRoles()
339
    {
340
        // Always return ROLE_USER
341
        $roles = [new Role('ROLE_USER')];
342
343
        if ($this->isGlobalAdministrator()) {
344
            $roles[] = new Role('ROLE_ADMIN');
345
        }
346
347
        return $roles;
348
    }
349
350
    /**
351
     * Set lastLogin
352
     *
353
     * @param \DateTime $lastLogin
354
     *
355
     * @return User
356
     */
357
    public function setLastLogin($lastLogin)
358
    {
359
        $this->lastLogin = $lastLogin;
360
361
        return $this;
362
    }
363
364
    /**
365
     * Get lastLogin
366
     *
367
     * @return \DateTime
368
     */
369
    public function getLastLogin()
370
    {
371
        return $this->lastLogin;
372
    }
373
374
    /**
375
     * Set group
376
     *
377
     * @param Group $group
378
     *
379
     * @return User
380
     */
381
    public function setStudentGroup(Group $group = null)
382
    {
383
        $this->studentGroup = $group;
384
385
        return $this;
386
    }
387
388
    /**
389
     * Get group
390
     *
391
     * @return Group
392
     */
393
    public function getStudentGroup()
394
    {
395
        return $this->studentGroup;
396
    }
397
398
    /**
399
     * Add tutorizedGroup
400
     *
401
     * @param Group $tutorizedGroup
402
     *
403
     * @return User
404
     */
405 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...
406
    {
407
        if (false === $this->tutorizedGroups->contains($tutorizedGroup)) {
408
            $this->tutorizedGroups[] = $tutorizedGroup;
409
            $tutorizedGroup->addTutor($this);
410
        }
411
412
        return $this;
413
    }
414
415
    /**
416
     * Remove tutorizedGroup
417
     *
418
     * @param Group $tutorizedGroup
419
     */
420 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...
421
    {
422
        if (true === $this->tutorizedGroups->contains($tutorizedGroup)) {
423
            $this->tutorizedGroups->removeElement($tutorizedGroup);
424
            $tutorizedGroup->removeTutor($this);
425
        }
426
    }
427
428
    /**
429
     * Get tutorizedGroups
430
     *
431
     * @return Collection
432
     */
433
    public function getTutorizedGroups()
434
    {
435
        return $this->tutorizedGroups;
436
    }
437
438
    /**
439
     * Add direct
440
     *
441
     * @param Department $direct
442
     *
443
     * @return User
444
     */
445
    public function addDirect(Department $direct)
446
    {
447
        $this->directs[] = $direct;
448
449
        return $this;
450
    }
451
452
    /**
453
     * Remove direct
454
     *
455
     * @param Department $direct
456
     */
457
    public function removeDirect(Department $direct)
458
    {
459
        $this->directs->removeElement($direct);
460
    }
461
462
    /**
463
     * Get directs
464
     *
465
     * @return Collection
466
     */
467
    public function getDirects()
468
    {
469
        return $this->directs;
470
    }
471
472
    /**
473
     * @Assert\Callback
474
     */
475
    public function validate(ExecutionContextInterface $context)
476
    {
477
        // comprobar si se ha especificado al menos el nombre de usuario o el correo electrónico
478
        if (!$this->getLoginUsername() && !$this->getEmail()) {
479
            $context->buildViolation('user.id.not_found')
480
                ->atPath('loginUsername')
481
                ->addViolation();
482
            $context->buildViolation('user.id.not_found')
483
                ->atPath('email')
484
                ->addViolation();
485
        }
486
    }
487
488
    /**
489
     * Returns the username used to authenticate the user.
490
     *
491
     * @return string The username
492
     */
493
    public function getUsername()
494
    {
495
        return $this->getLoginUsername() ?: $this->getEmail();
496
    }
497
}
498