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 — master ( 57b2f6...3e832a )
by Luis Ramón
04:08
created

User::removeTutorizedGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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\ArrayCollection;
24
use Doctrine\Common\Collections\Collection;
25
use Doctrine\ORM\Mapping as ORM;
26
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
27
use Symfony\Component\Security\Core\Role\Role;
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
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="boolean")
87
     * @var bool
88
     */
89
    protected $financialManager;
90
91
    /**
92
     * @ORM\Column(type="boolean")
93
     * @var bool
94
     */
95
    protected $allowExternalLogin;
96
97
    /**
98
     * @ORM\Column(type="boolean")
99
     * @var bool
100
     */
101
    protected $externalLogin;
102
103
    /**
104
     * @ORM\Column(type="datetime", nullable=true)
105
     * @var \DateTime
106
     */
107
    protected $lastLogin;
108
109
    /**
110
     * @ORM\ManyToOne(targetEntity="Group", inversedBy="students")
111
     *
112
     * @var Group
113
     */
114
    protected $studentGroup;
115
116
    /**
117
     * @ORM\ManyToMany(targetEntity="Group", mappedBy="tutors", fetch="EXTRA_LAZY")
118
     * @ORM\JoinTable(name="tutorized_groups")
119
     *
120
     * @var Collection
121
     */
122
    protected $tutorizedGroups;
123
124
    /**
125
     * @ORM\OneToMany(targetEntity="Department", mappedBy="head", fetch="EXTRA_LAZY")
126
     *
127
     * @var Collection
128
     */
129
    protected $directs;
130
131
    /**
132
     * @ORM\OneToMany(targetEntity="Agreement", mappedBy="student", fetch="EXTRA_LAZY")
133
     * @ORM\OrderBy({"fromDate": "ASC"})
134
     *
135
     * @var Collection
136
     */
137
    protected $studentAgreements;
138
139
    /**
140
     * @ORM\OneToMany(targetEntity="Agreement", mappedBy="educationalTutor", fetch="EXTRA_LAZY")
141
     * @ORM\OrderBy({"fromDate": "ASC"})
142
     *
143
     * @var Collection
144
     */
145
    protected $educationalTutorAgreements;
146
147
    /**
148
     * @ORM\OneToMany(targetEntity="Agreement", mappedBy="workTutor", fetch="EXTRA_LAZY")
149
     * @ORM\OrderBy({"fromDate": "ASC"})
150
     *
151
     * @var Collection
152
     */
153
    protected $workTutorAgreements;
154
155
    /**
156
     * @ORM\OneToMany(targetEntity="Expense", mappedBy="teacher", fetch="EXTRA_LAZY")
157
     * @ORM\OrderBy({"date": "ASC"})
158
     *
159
     * @var Collection
160
     */
161
    protected $expenses;
162
163
    /**
164
     * @ORM\OneToMany(targetEntity="Visit", mappedBy="tutor", fetch="EXTRA_LAZY")
165
     * @ORM\OrderBy({"date": "ASC"})
166
     * @var Collection
167
     */
168
    protected $visits;
169
170
    /**
171
     * Constructor
172
     */
173
    public function __construct()
174
    {
175
        parent::__construct();
176
177
        $this->tutorizedGroups = new ArrayCollection();
178
        $this->directs = new ArrayCollection();
179
        $this->studentAgreements = new ArrayCollection();
180
        $this->educationalTutorAgreements = new ArrayCollection();
181
        $this->workTutorAgreements = new ArrayCollection();
182
        $this->expenses = new ArrayCollection();
183
        $this->visits = new ArrayCollection();
184
185
        $this->allowExternalLogin = false;
186
        $this->externalLogin = false;
187
    }
188
189
    /**
190
     * Returns the person's display name
191
     *
192
     * @return string
193
     */
194
    public function getFullDisplayName()
195
    {
196
        $displayName = (string) $this;
197
198
        if (null !== $this->getStudentGroup()) {
199
            $displayName .= ' (' . (string) $this->getStudentGroup() . ')';
200
        }
201
202
        return $displayName;
203
    }
204
205
    /**
206
     * Returns the person's display name
207
     *
208
     * @return string
209
     */
210
    public function getFullPersonDisplayName()
211
    {
212
        $displayName = (string) $this;
213
214
        if (null !== $this->getReference()) {
215
            $displayName .= ' (' . $this->getReference() . ')';
216
        }
217
218
        return $displayName;
219
    }
220
221
    /**
222
     * Get id
223
     *
224
     * @return integer
225
     */
226
    public function getId()
227
    {
228
        return $this->id;
229
    }
230
231
    /**
232
     * Get login username
233
     *
234
     * @return string
235
     */
236
    public function getLoginUsername()
237
    {
238
        return $this->loginUsername;
239
    }
240
241
    /**
242
     * Set login username
243
     *
244
     * @param string $loginUsername
245
     *
246
     * @return User
247
     */
248
    public function setLoginUsername($loginUsername)
249
    {
250
        $this->loginUsername = $loginUsername;
251
252
        return $this;
253
    }
254
255
    /**
256
     * Get password
257
     *
258
     * @return string
259
     */
260
    public function getPassword()
261
    {
262
        return $this->password;
263
    }
264
265
    /**
266
     * Set password
267
     *
268
     * @param string $password
269
     *
270
     * @return User
271
     */
272
    public function setPassword($password)
273
    {
274
        $this->password = $password;
275
276
        return $this;
277
    }
278
279
    /**
280
     * Get token
281
     *
282
     * @return string
283
     */
284
    public function getToken()
285
    {
286
        return $this->token;
287
    }
288
289
    /**
290
     * Set token
291
     *
292
     * @param string $token
293
     *
294
     * @return User
295
     */
296
    public function setToken($token)
297
    {
298
        $this->token = $token;
299
300
        return $this;
301
    }
302
303
    /**
304
     * Get tokenValidity
305
     *
306
     * @return \DateTime
307
     */
308
    public function getTokenValidity()
309
    {
310
        return $this->tokenValidity;
311
    }
312
313
    /**
314
     * Set tokenValidity
315
     *
316
     * @param \DateTime $tokenValidity
317
     *
318
     * @return User
319
     */
320
    public function setTokenValidity($tokenValidity)
321
    {
322
        $this->tokenValidity = $tokenValidity;
323
324
        return $this;
325
    }
326
327
    /**
328
     * Get enabled
329
     *
330
     * @return boolean
331
     */
332
    public function isEnabled()
333
    {
334
        return $this->enabled;
335
    }
336
337
    /**
338
     * Set enabled
339
     *
340
     * @param boolean $enabled
341
     *
342
     * @return User
343
     */
344
    public function setEnabled($enabled)
345
    {
346
        $this->enabled = $enabled;
347
348
        return $this;
349
    }
350
351
    /**
352
     * Get globalAdministrator
353
     *
354
     * @return boolean
355
     */
356
    public function isGlobalAdministrator()
357
    {
358
        return $this->globalAdministrator;
359
    }
360
361
    /**
362
     * Set globalAdministrator
363
     *
364
     * @param boolean $globalAdministrator
365
     *
366
     * @return User
367
     */
368
    public function setGlobalAdministrator($globalAdministrator)
369
    {
370
        $this->globalAdministrator = $globalAdministrator;
371
372
        return $this;
373
    }
374
375
    /**
376
     * String representation of object
377
     * @link http://php.net/manual/en/serializable.serialize.php
378
     * @return string the string representation of the object or null
379
     * @since 5.1.0
380
     */
381
    public function serialize()
382
    {
383
        return serialize(array(
384
            $this->id,
385
            $this->email,
386
            $this->loginUsername,
387
            $this->password
388
        ));
389
    }
390
391
    /**
392
     * Constructs the object
393
     * @link http://php.net/manual/en/serializable.unserialize.php
394
     * @param string $serialized <p>
395
     * The string representation of the object.
396
     * </p>
397
     * @return void
398
     * @since 5.1.0
399
     */
400
    public function unserialize($serialized)
401
    {
402
        list (
403
            $this->id,
404
            $this->email,
405
            $this->loginUsername,
406
            $this->password
407
        ) = unserialize($serialized);
408
    }
409
410
    /**
411
     * Returns the salt that was originally used to encode the password.
412
     *
413
     * This can return null if the password was not encoded using a salt.
414
     *
415
     * @return string|null The salt
416
     */
417
    public function getSalt()
418
    {
419
        return null;
420
    }
421
422
    /**
423
     * Removes sensitive data from the user.
424
     *
425
     * This is important if, at any given point, sensitive information like
426
     * the plain-text password is stored on this object.
427
     */
428
    public function eraseCredentials()
429
    {
430
    }
431
432
    /**
433
     * Returns the roles granted to the user.
434
     *
435
     * @return Role[] The user roles
436
     */
437
    public function getRoles()
438
    {
439
        // Always return ROLE_USER
440
        $roles = [new Role('ROLE_USER')];
441
442
        if ($this->isGlobalAdministrator()) {
443
            $roles[] = new Role('ROLE_ADMIN');
444
        }
445
446
        if ($this->tutorizedGroups && $this->tutorizedGroups->count()) {
447
            $roles[] = new Role('ROLE_GROUP_TUTOR');
448
        }
449
450
        if ($this->directs && $this->directs->count()) {
451
            $roles[] = new Role('ROLE_DEPARTMENT_HEAD');
452
        }
453
454
        if ($this->educationalTutorAgreements && $this->educationalTutorAgreements->count()) {
455
            $roles[] = new Role('ROLE_EDUCATIONAL_TUTOR');
456
        }
457
458
        if ($this->studentGroup) {
459
            $roles[] = new Role('ROLE_STUDENT');
460
        }
461
        if ($this->isFinancialManager()) {
462
            $roles[] = new Role('ROLE_FINANCIAL_MANAGER');
463
        }
464
465
        return $roles;
466
    }
467
468
    /**
469
     * Set lastLogin
470
     *
471
     * @param \DateTime $lastLogin
472
     *
473
     * @return User
474
     */
475
    public function setLastLogin($lastLogin)
476
    {
477
        $this->lastLogin = $lastLogin;
478
479
        return $this;
480
    }
481
482
    /**
483
     * Get lastLogin
484
     *
485
     * @return \DateTime
486
     */
487
    public function getLastLogin()
488
    {
489
        return $this->lastLogin;
490
    }
491
492
    /**
493
     * Set group
494
     *
495
     * @param Group $group
496
     *
497
     * @return User
498
     */
499
    public function setStudentGroup(Group $group = null)
500
    {
501
        $this->studentGroup = $group;
502
503
        return $this;
504
    }
505
506
    /**
507
     * Get group
508
     *
509
     * @return Group
510
     */
511
    public function getStudentGroup()
512
    {
513
        return $this->studentGroup;
514
    }
515
516
    /**
517
     * Add tutorizedGroup
518
     *
519
     * @param Group $tutorizedGroup
520
     *
521
     * @return User
522
     */
523
    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...
524
    {
525
        if (false === $this->tutorizedGroups->contains($tutorizedGroup)) {
526
            $this->tutorizedGroups[] = $tutorizedGroup;
527
            $tutorizedGroup->addTutor($this);
528
        }
529
530
        return $this;
531
    }
532
533
    /**
534
     * Remove tutorizedGroup
535
     *
536
     * @param Group $tutorizedGroup
537
     */
538
    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...
539
    {
540
        if (true === $this->tutorizedGroups->contains($tutorizedGroup)) {
541
            $this->tutorizedGroups->removeElement($tutorizedGroup);
542
            $tutorizedGroup->removeTutor($this);
543
        }
544
    }
545
546
    /**
547
     * Get tutorizedGroups
548
     *
549
     * @return Collection
550
     */
551
    public function getTutorizedGroups()
552
    {
553
        return $this->tutorizedGroups;
554
    }
555
556
    /**
557
     * Add direct
558
     *
559
     * @param Department $direct
560
     *
561
     * @return User
562
     */
563
    public function addDirect(Department $direct)
564
    {
565
        $this->directs[] = $direct;
566
567
        return $this;
568
    }
569
570
    /**
571
     * Remove direct
572
     *
573
     * @param Department $direct
574
     */
575
    public function removeDirect(Department $direct)
576
    {
577
        $this->directs->removeElement($direct);
578
    }
579
580
    /**
581
     * Get directs
582
     *
583
     * @return Collection
584
     */
585
    public function getDirects()
586
    {
587
        return $this->directs;
588
    }
589
590
    /**
591
     * @Assert\Callback
592
     */
593
    public function validate(ExecutionContextInterface $context)
594
    {
595
        // comprobar si se ha especificado al menos el nombre de usuario o el correo electrónico
596
        if (!$this->getLoginUsername() && !$this->getEmail()) {
597
            $context->buildViolation('user.id.not_found')
598
                ->atPath('loginUsername')
599
                ->addViolation();
600
            $context->buildViolation('user.id.not_found')
601
                ->atPath('email')
602
                ->addViolation();
603
        }
604
    }
605
606
    /**
607
     * Returns the username used to authenticate the user.
608
     *
609
     * @return string The username
610
     */
611
    public function getUsername()
612
    {
613
        return $this->getLoginUsername() ?: $this->getEmail();
614
    }
615
616
    /**
617
     * Add studentAgreement
618
     *
619
     * @param Agreement $studentAgreement
620
     *
621
     * @return User
622
     */
623
    public function addStudentAgreement(Agreement $studentAgreement)
624
    {
625
        $this->studentAgreements[] = $studentAgreement;
626
627
        return $this;
628
    }
629
630
    /**
631
     * Remove studentAgreement
632
     *
633
     * @param Agreement $studentAgreement
634
     */
635
    public function removeStudentAgreement(Agreement $studentAgreement)
636
    {
637
        $this->studentAgreements->removeElement($studentAgreement);
638
    }
639
640
    /**
641
     * Get studentAgreements
642
     *
643
     * @return Collection
644
     */
645
    public function getStudentAgreements()
646
    {
647
        return $this->studentAgreements;
648
    }
649
650
    /**
651
     * Add educationalTutorAgreement
652
     *
653
     * @param Agreement $educationalTutorAgreement
654
     *
655
     * @return User
656
     */
657
    public function addEducationalTutorAgreement(Agreement $educationalTutorAgreement)
658
    {
659
        $this->educationalTutorAgreements[] = $educationalTutorAgreement;
660
661
        return $this;
662
    }
663
664
    /**
665
     * Remove educationalTutorAgreement
666
     *
667
     * @param Agreement $educationalTutorAgreement
668
     */
669
    public function removeEducationalTutorAgreement(Agreement $educationalTutorAgreement)
670
    {
671
        $this->educationalTutorAgreements->removeElement($educationalTutorAgreement);
672
    }
673
674
    /**
675
     * Get educationalTutorAgreements
676
     *
677
     * @return Collection
678
     */
679
    public function getEducationalTutorAgreements()
680
    {
681
        return $this->educationalTutorAgreements;
682
    }
683
684
    /**
685
     * Add workTutorAgreement
686
     *
687
     * @param Agreement $workTutorAgreement
688
     *
689
     * @return User
690
     */
691
    public function addWorkTutorAgreement(Agreement $workTutorAgreement)
692
    {
693
        $this->workTutorAgreements[] = $workTutorAgreement;
694
695
        return $this;
696
    }
697
698
    /**
699
     * Remove workTutorAgreement
700
     *
701
     * @param Agreement $workTutorAgreement
702
     */
703
    public function removeWorkTutorAgreement(Agreement $workTutorAgreement)
704
    {
705
        $this->workTutorAgreements->removeElement($workTutorAgreement);
706
    }
707
708
    /**
709
     * Get workTutorAgreements
710
     *
711
     * @return Collection
712
     */
713
    public function getWorkTutorAgreements()
714
    {
715
        return $this->workTutorAgreements;
716
    }
717
718
    /**
719
     * Add expense
720
     *
721
     * @param \AppBundle\Entity\Expense $expense
722
     *
723
     * @return User
724
     */
725
    public function addExpense(\AppBundle\Entity\Expense $expense)
726
    {
727
        $this->expenses[] = $expense;
728
729
        return $this;
730
    }
731
732
    /**
733
     * Remove expense
734
     *
735
     * @param \AppBundle\Entity\Expense $expense
736
     */
737
    public function removeExpense(\AppBundle\Entity\Expense $expense)
738
    {
739
        $this->expenses->removeElement($expense);
740
    }
741
742
    /**
743
     * Get expenses
744
     *
745
     * @return Collection
746
     */
747
    public function getExpenses()
748
    {
749
        return $this->expenses;
750
    }
751
752
    /**
753
     * Add visit
754
     *
755
     * @param Visit $visit
756
     *
757
     * @return User
758
     */
759
    public function addVisit(Visit $visit)
760
    {
761
        $this->visits[] = $visit;
762
763
        return $this;
764
    }
765
766
    /**
767
     * Remove visit
768
     *
769
     * @param Visit $visit
770
     */
771
    public function removeVisit(Visit $visit)
772
    {
773
        $this->visits->removeElement($visit);
774
    }
775
776
    /**
777
     * Get visits
778
     *
779
     * @return Collection
780
     */
781
    public function getVisits()
782
    {
783
        return $this->visits;
784
    }
785
786
    /**
787
     * Set financialManager
788
     *
789
     * @param boolean $financialManager
790
     *
791
     * @return User
792
     */
793
    public function setFinancialManager($financialManager)
794
    {
795
        $this->financialManager = $financialManager;
796
797
        return $this;
798
    }
799
800
    /**
801
     * Get financialManager
802
     *
803
     * @return boolean
804
     */
805
    public function isFinancialManager()
806
    {
807
        return $this->financialManager;
808
    }
809
810
    /**
811
     * Get allowExternalLogin
812
     *
813
     * @return bool
814
     */
815
    public function getAllowExternalLogin()
816
    {
817
        return $this->allowExternalLogin;
818
    }
819
820
    /**
821
     * Set allowExternalLogin
822
     *
823
     * @param bool $allowExternalLogin
824
     *
825
     * @return User
826
     */
827
    public function setAllowExternalLogin($allowExternalLogin)
828
    {
829
        $this->allowExternalLogin = $allowExternalLogin;
830
        return $this;
831
    }
832
833
    /**
834
     * Has externalLogin
835
     *
836
     * @return bool
837
     */
838
    public function hasExternalLogin()
839
    {
840
        return $this->externalLogin;
841
    }
842
843
    /**
844
     * Set externalLogin
845
     *
846
     * @param bool $externalLogin
847
     * @return User
848
     */
849
    public function setExternalLogin($externalLogin)
850
    {
851
        $this->externalLogin = $externalLogin;
852
        return $this;
853
    }
854
}
855