Failed Conditions
Push — master ( 0fd122...b2f91e )
by Adrien
06:52
created

User::setHasInsurance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Acl\Acl;
8
use Application\Api\Exception;
9
use Application\DBAL\Types\BillingTypeType;
10
use Application\DBAL\Types\RelationshipType;
11
use Application\ORM\Query\Filter\AclFilter;
12
use Application\Traits\HasAddress;
13
use Application\Traits\HasDoorAccess;
14
use Application\Traits\HasRemarks;
15
use Application\Utility;
16
use Cake\Chronos\Chronos;
17
use Cake\Chronos\Date;
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Doctrine\Common\Collections\Collection;
20
use Doctrine\ORM\Mapping as ORM;
21
use GraphQL\Doctrine\Annotation as API;
22
23
/**
24
 * User
25
 *
26
 * @ORM\Entity(repositoryClass="Application\Repository\UserRepository")
27
 * @ORM\AssociationOverrides({
28
 *     @ORM\AssociationOverride(name="owner", inversedBy="users")
29
 * })
30
 */
31
class User extends AbstractModel
32
{
33
    const ROLE_ANONYMOUS = 'anonymous';
34
    const ROLE_BOOKING_ONLY = 'booking_only';
35
    const ROLE_INDIVIDUAL = 'individual';
36
    const ROLE_MEMBER = 'member';
37
    const ROLE_RESPONSIBLE = 'responsible';
38
    const ROLE_ADMINISTRATOR = 'administrator';
39
40
    const STATUS_INACTIVE = 'inactive';
41
    const STATUS_NEW = 'new';
42
    const STATUS_ACTIVE = 'active';
43
    const STATUS_ARCHIVED = 'archived';
44
45
    use HasDoorAccess;
46
    use HasRemarks;
47
    use HasAddress;
48
49
    /**
50
     * @var User
51
     */
52
    private static $currentUser;
53
54
    /**
55
     * Set currently logged in user
56
     * WARNING: this method should only be called from \Application\Authentication\AuthenticationListener
57
     *
58
     * @param \Application\Model\User $user
59
     */
60 55
    public static function setCurrent(?self $user): void
61
    {
62 55
        self::$currentUser = $user;
63
64
        // Initalize ACL filter with current user if a logged in one exists
65 55
        _em()->getFilters()->getFilter(AclFilter::class)->setUser($user);
66 55
    }
67
68
    /**
69
     * Returns currently logged user or null
70
     *
71
     * @return null|self
72
     */
73 44
    public static function getCurrent(): ?self
74
    {
75 44
        return self::$currentUser;
76
    }
77
78
    /**
79
     * @var null|string
80
     *
81
     * @ORM\Column(type="string", length=50, nullable=true, unique=true)
82
     */
83
    private $login;
84
85
    /**
86
     * @var string
87
     * @ORM\Column(type="string", length=191)
88
     */
89
    private $firstName = '';
90
91
    /**
92
     * @var string
93
     * @ORM\Column(type="string", length=191)
94
     */
95
    private $lastName = '';
96
97
    /**
98
     * @var string
99
     *
100
     * @ORM\Column(type="string", length=255)
101
     */
102
    private $password = '';
103
104
    /**
105
     * @var null|string
106
     * @ORM\Column(type="string", length=191, nullable=true, unique=true)
107
     */
108
    private $email;
109
110
    /**
111
     * @var string
112
     * @ORM\Column(type="UserRole", options={"default" = User::ROLE_INDIVIDUAL})
113
     */
114
    private $role = self::ROLE_INDIVIDUAL;
115
116
    /**
117
     * @var string
118
     * @ORM\Column(type="UserStatus", options={"default" = User::STATUS_NEW})
119
     */
120
    private $status = self::STATUS_NEW;
121
122
    /**
123
     * @var null|Chronos
124
     * @ORM\Column(type="datetime", nullable=true)
125
     */
126
    private $lastLogin;
127
128
    /**
129
     * @var null|Chronos
130
     * @ORM\Column(type="datetime", nullable=true)
131
     */
132
    private $welcomeSessionDate;
133
134
    /**
135
     * @var int sex according to ISO/IEC 5218
136
     * @ORM\Column(type="smallint", options={"default" = 0}))
137
     */
138
    private $sex = 0;
139
140
    /**
141
     * @var string
142
     * @ORM\Column(type="string", length=25, options={"default" = ""})
143
     */
144
    private $phone = '';
145
146
    /**
147
     * @var string
148
     * @ORM\Column(type="string", length=25, options={"default" = ""})
149
     */
150
    private $mobilePhone = '';
151
152
    /**
153
     * @var string
154
     * @ORM\Column(type="string", length=25, options={"default" = ""})
155
     */
156
    private $ichtusSwissSailing = '';
157
158
    /**
159
     * @var null|Date
160
     * @ORM\Column(type="date", nullable=true)
161
     */
162
    private $birthday;
163
164
    /**
165
     * @var bool
166
     * @ORM\Column(type="boolean", options={"default" = 0})
167
     */
168
    private $termsAgreement = false;
169
170
    /**
171
     * @var bool
172
     * @ORM\Column(type="boolean", options={"default" = 0})
173
     */
174
    private $hasInsurance = false;
175
176
    /**
177
     * @var bool
178
     * @ORM\Column(type="boolean", options={"default" = 0})
179
     */
180
    private $receivesNewsletter = false;
181
182
    /**
183
     * @var string
184
     * @ORM\Column(type="Relationship", options={"default" = RelationshipType::HOUSEHOLDER})
185
     */
186
    private $familyRelationship = RelationshipType::HOUSEHOLDER;
187
188
    /**
189
     * @var string
190
     * @ORM\Column(type="BillingType", options={"default" = BillingTypeType::ALL_ELECTRONIC})
191
     */
192
    private $billingType = BillingTypeType::ALL_ELECTRONIC;
193
194
    /**
195
     * @var null|string
196
     * @ORM\Column(type="string", length=32, nullable=true, unique=true)
197
     */
198
    private $token;
199
200
    /**
201
     * @var null|Chronos
202
     *
203
     * @ORM\Column(type="datetime", nullable=true)
204
     */
205
    private $tokenCreationDate;
206
207
    /**
208
     * @var Collection
209
     * @ORM\OneToMany(targetEntity="Booking", mappedBy="owner")
210
     */
211
    private $bookings;
212
213
    /**
214
     * @var Collection
215
     * @ORM\ManyToMany(targetEntity="License", mappedBy="users")
216
     */
217
    private $licenses;
218
219
    /**
220
     * @var Collection
221
     * @ORM\ManyToMany(targetEntity="UserTag", mappedBy="users")
222
     */
223
    private $userTags;
224
225
    /**
226
     * @var Collection
227
     * @ORM\OneToMany(targetEntity="Message", mappedBy="recipient")
228
     */
229
    private $messages;
230
231
    /**
232
     * There is actually 0 to 1 account, never more. And this is
233
     * enforced by DB unique constraints
234
     *
235
     * @var Collection
236
     * @ORM\OneToMany(targetEntity="Account", mappedBy="owner")
237
     */
238
    private $accounts;
239
240
    /**
241
     * @var Collection
242
     * @ORM\OneToMany(targetEntity="User", mappedBy="owner")
243
     */
244
    private $users;
245
246
    /**
247
     * Constructor
248
     *
249
     * @param string $role role for new user
250
     */
251 28
    public function __construct(string $role = self::ROLE_INDIVIDUAL)
252
    {
253 28
        $this->role = $role;
254 28
        $this->bookings = new ArrayCollection();
255 28
        $this->accounts = new ArrayCollection();
256 28
        $this->licenses = new ArrayCollection();
257 28
        $this->userTags = new ArrayCollection();
258 28
        $this->messages = new ArrayCollection();
259 28
        $this->users = new ArrayCollection();
260 28
    }
261
262
    /**
263
     * Set login (eg: johndoe)
264
     *
265
     * @API\Input(type="Login")
266
     *
267
     * @param string $login
268
     */
269 1
    public function setLogin(string $login): void
270
    {
271 1
        $this->login = $login;
272 1
    }
273
274
    /**
275
     * Get login (eg: johndoe)
276
     *
277
     * @API\Field(type="?Login")
278
     *
279
     * @return null|string
280
     */
281 12
    public function getLogin(): ?string
282
    {
283 12
        return $this->login;
284
    }
285
286
    /**
287
     * Hash and change the user password
288
     *
289
     * @param string $password
290
     */
291 5
    public function setPassword(string $password): void
292
    {
293
        // Ignore empty password that could be sent "by mistake" by the client
294
        // when agreeing to terms
295 5
        if ($password === '') {
296 1
            return;
297
        }
298
299 5
        $this->revokeToken();
300
301 5
        $this->password = password_hash($password, PASSWORD_DEFAULT);
302 5
    }
303
304
    /**
305
     * Returns the hashed password
306
     *
307
     * @API\Exclude
308
     *
309
     * @return string
310
     */
311 3
    public function getPassword(): string
312
    {
313 3
        return $this->password;
314
    }
315
316
    /**
317
     * Set first name
318
     *
319
     * @param string $firstName
320
     */
321 1
    public function setFirstName($firstName): void
322
    {
323 1
        $this->firstName = $firstName;
324 1
    }
325
326
    /**
327
     * Get first name
328
     *
329
     * @return string
330
     */
331 4
    public function getFirstName(): string
332
    {
333 4
        return (string) $this->firstName;
334
    }
335
336
    /**
337
     * Set last name
338
     *
339
     * @param string $lastName
340
     */
341 1
    public function setLastName($lastName): void
342
    {
343 1
        $this->lastName = $lastName;
344 1
    }
345
346
    /**
347
     * Get last name
348
     *
349
     * @return string
350
     */
351 1
    public function getLastName(): string
352
    {
353 1
        return (string) $this->lastName;
354
    }
355
356
    /**
357
     * Get full name
358
     *
359
     * @return string
360
     */
361 1
    public function getName(): string
362
    {
363 1
        return implode(' ', [$this->getFirstName(), $this->getLastName()]);
364
    }
365
366
    /**
367
     * Set email
368
     *
369
     * @API\Input(type="?Email")
370
     *
371
     * @param string $email
372
     */
373 3
    public function setEmail(string $email): void
374
    {
375 3
        $this->email = $email;
376 3
    }
377
378
    /**
379
     * Get email
380
     *
381
     * @API\Field(type="?Email")
382
     *
383
     * @return null|string
384
     */
385 5
    public function getEmail(): ?string
386
    {
387 5
        return $this->email;
388
    }
389
390
    /**
391
     * Returns whether the user is administrator and thus have can do anything.
392
     *
393
     * @API\Field(type="Application\Api\Enum\UserRoleType")
394
     */
395 30
    public function getRole(): string
396
    {
397 30
        return $this->role;
398
    }
399
400
    /**
401
     * Sets the user role
402
     *
403
     * The current user is allowed to promote another user up to the same role as himself. So
404
     * a Senior can promote a Student to Senior. Or an Admin can promote a Junior to Admin.
405
     *
406
     * But the current user is **not** allowed to demote a user who has a higher role than himself.
407
     * That means that a Senior cannot demote an Admin to Student.
408
     *
409
     * @param string $role
410
     */
411 7
    public function setRole(string $role): void
412
    {
413 7
        if ($role === $this->role) {
414 2
            return;
415
        }
416
417 5
        $currentRole = self::getCurrent() ? self::getCurrent()->getRole() : self::ROLE_ANONYMOUS;
418
        $orderedRoles = [
419 5
            self::ROLE_ANONYMOUS,
420 5
            self::ROLE_INDIVIDUAL,
421 5
            self::ROLE_MEMBER,
422 5
            self::ROLE_RESPONSIBLE,
423 5
            self::ROLE_ADMINISTRATOR,
424
        ];
425
426 5
        $newFound = false;
427 5
        $oldFound = false;
428 5
        foreach ($orderedRoles as $r) {
429 5
            if ($r === $this->role) {
430 3
                $oldFound = true;
431
            }
432 5
            if ($r === $role) {
433 2
                $newFound = true;
434
            }
435
436 5
            if ($r === $currentRole) {
437 5
                break;
438
            }
439
        }
440
441 5
        if (!$newFound || !$oldFound) {
442 3
            throw new Exception($currentRole . ' is not allowed to change role to ' . $role);
443
        }
444
445 2
        $this->role = $role;
446 2
    }
447
448 5
    public function setOwner(self $owner = null): void
449
    {
450 5
        if ($owner && $owner !== $this) {
451 4
            if ($owner->getOwner() && $owner !== $owner->getOwner()) {
452 1
                throw new Exception('This user cannot be owned by a user who is himself owned by somebody else');
453
            }
454
455 4
            if ($this->users->count()) {
456 1
                throw new Exception('This user owns other users, so he cannot himself be owned by somebody else');
457
            }
458
        }
459
460 5
        if ($this->getOwner()) {
461
            $this->getOwner()->users->removeElement($this);
462
        }
463
464 5
        parent::setOwner($owner);
465
466 5
        if ($this->getOwner()) {
467 4
            $this->getOwner()->users->add($this);
468 4
            $this->setStatus($this->getOwner()->getStatus());
469
        }
470 5
    }
471
472
    /**
473
     * @API\Field(type="Application\Api\Enum\UserStatusType")
474
     *
475
     * @return string
476
     */
477 4
    public function getStatus(): string
478
    {
479 4
        return $this->status;
480
    }
481
482
    /**
483
     * @API\Input(type="Application\Api\Enum\UserStatusType")
484
     *
485
     * @param string $status
486
     */
487 5
    public function setStatus(string $status): void
488
    {
489 5
        $this->status = $status;
490 5
        $this->revokeToken();
491
492 5
        foreach ($this->users as $user) {
493 3
            if ($user !== $this) {
494 1
                $user->setStatus($status);
495
            }
496
        }
497 5
    }
498
499
    /**
500
     * Get a list of global permissions for this user
501
     *
502
     * @API\Field(type="GlobalPermissionsList")
503
     *
504
     * @return array
505
     */
506 3
    public function getGlobalPermissions(): array
507
    {
508 3
        $acl = new Acl();
509
        $types = [
510 3
            Account::class,
511
            AccountingDocument::class,
512
            Bookable::class,
513
            BookableMetadata::class,
514
            BookableTag::class,
515
            Booking::class,
516
            Category::class,
517
            Country::class,
518
            ExpenseClaim::class,
519
            Image::class,
520
            License::class,
521
            Message::class,
522
            self::class,
523
            UserTag::class,
524
        ];
525
526 3
        $permissions = ['create'];
527 3
        $result = [];
528
529 3
        $previousUser = self::getCurrent();
530 3
        self::setCurrent($this);
531 3
        foreach ($types as $type) {
532 3
            $instance = new $type();
533
534 3
            if ($instance instanceof AccountingDocument) {
535 3
                $instance->setExpenseClaim(new ExpenseClaim());
536
            }
537
538 3
            $sh = lcfirst(Utility::getShortClassName($instance));
539 3
            $result[$sh] = [];
540
541 3
            foreach ($permissions as $p) {
542 3
                $result[$sh][$p] = $acl->isCurrentUserAllowed($instance, $p);
543
            }
544
        }
545
546 3
        self::setCurrent($previousUser);
547
548 3
        return $result;
549
    }
550
551
    /**
552
     * @return string
553
     */
554
    public function getPhone(): string
555
    {
556
        return $this->phone;
557
    }
558
559
    /**
560
     * @param string $phone
561
     */
562
    public function setPhone(string $phone): void
563
    {
564
        $this->phone = $phone;
565
    }
566
567
    /**
568
     * @return string
569
     */
570
    public function getMobilePhone(): string
571
    {
572
        return $this->mobilePhone;
573
    }
574
575
    /**
576
     * @param string $mobilePhone
577
     */
578
    public function setMobilePhone(string $mobilePhone): void
579
    {
580
        $this->mobilePhone = $mobilePhone;
581
    }
582
583
    /**
584
     * @return null|Date
585
     */
586
    public function getBirthday(): ?Date
587
    {
588
        return $this->birthday;
589
    }
590
591
    /**
592
     * @param null|Date $birthday
593
     */
594
    public function setBirthday(?Date $birthday): void
595
    {
596
        $this->birthday = $birthday;
597
    }
598
599
    /**
600
     * Get bookings
601
     *
602
     * @return Collection
603
     */
604 1
    public function getBookings(): Collection
605
    {
606 1
        return $this->bookings;
607
    }
608
609
    /**
610
     * Notify the user that it has a new booking.
611
     * This should only be called by Booking::setResponsible()
612
     *
613
     * @param Booking $booking
614
     */
615 7
    public function bookingAdded(Booking $booking): void
616
    {
617 7
        $this->bookings->add($booking);
618 7
    }
619
620
    /**
621
     * Notify the user that it has a booking was removed.
622
     * This should only be called by Booking::setResponsible()
623
     *
624
     * @param Booking $booking
625
     */
626 3
    public function bookingRemoved(Booking $booking): void
627
    {
628 3
        $this->bookings->removeElement($booking);
629 3
    }
630
631
    /**
632
     * @return Collection
633
     */
634 1
    public function getLicenses(): Collection
635
    {
636 1
        return $this->licenses;
637
    }
638
639
    /**
640
     * @return Collection
641
     */
642 1
    public function getUserTags(): Collection
643
    {
644 1
        return $this->userTags;
645
    }
646
647
    /**
648
     * Notify the user that it has a new license.
649
     * This should only be called by License::addUser()
650
     *
651
     * @param License $license
652
     */
653 1
    public function licenseAdded(License $license): void
654
    {
655 1
        $this->licenses->add($license);
656 1
    }
657
658
    /**
659
     * Notify the user that it a license was removed.
660
     * This should only be called by License::removeUser()
661
     *
662
     * @param License $license
663
     */
664 1
    public function licenseRemoved(License $license): void
665
    {
666 1
        $this->licenses->removeElement($license);
667 1
    }
668
669
    /**
670
     * Notify the user that it has a new userTag.
671
     * This should only be called by UserTag::addUser()
672
     *
673
     * @param UserTag $userTag
674
     */
675 1
    public function userTagAdded(UserTag $userTag): void
676
    {
677 1
        $this->userTags->add($userTag);
678 1
    }
679
680
    /**
681
     * Notify the user that a userTag was removed.
682
     * This should only be called by UserTag::removeUser()
683
     *
684
     * @param UserTag $userTag
685
     */
686 1
    public function userTagRemoved(UserTag $userTag): void
687
    {
688 1
        $this->userTags->removeElement($userTag);
689 1
    }
690
691
    /**
692
     * @return bool
693
     */
694
    public function isTermsAgreement(): bool
695
    {
696
        return $this->termsAgreement;
697
    }
698
699
    /**
700
     * @param bool $termsAgreement
701
     */
702 1
    public function setTermsAgreement(bool $termsAgreement): void
703
    {
704 1
        $this->termsAgreement = $termsAgreement;
705 1
    }
706
707
    /**
708
     * @return bool
709
     */
710
    public function getHasInsurance(): bool
711
    {
712
        return $this->hasInsurance;
713
    }
714
715
    /**
716
     * @param bool $hasInsurance
717
     */
718 1
    public function setHasInsurance(bool $hasInsurance): void
719
    {
720 1
        $this->hasInsurance = $hasInsurance;
721 1
    }
722
723
    /**
724
     * @return null|Chronos
725
     */
726
    public function getWelcomeSessionDate(): ?Chronos
727
    {
728
        return $this->welcomeSessionDate;
729
    }
730
731
    /**
732
     * @param null|Chronos $welcomeSessionDate
733
     */
734
    public function setWelcomeSessionDate(?Chronos $welcomeSessionDate): void
735
    {
736
        $this->welcomeSessionDate = $welcomeSessionDate;
737
    }
738
739
    /**
740
     * @return bool
741
     */
742
    public function isReceivesNewsletter(): bool
743
    {
744
        return $this->receivesNewsletter;
745
    }
746
747
    /**
748
     * @param bool $receivesNewsletter
749
     */
750
    public function setReceivesNewsletter(bool $receivesNewsletter): void
751
    {
752
        $this->receivesNewsletter = $receivesNewsletter;
753
    }
754
755
    /**
756
     * Get the ISO/IEC 5218 sex
757
     *
758
     * @API\Field(type="Sex")
759
     *
760
     * @return int
761
     */
762
    public function getSex(): int
763
    {
764
        return $this->sex;
765
    }
766
767
    /**
768
     * Set the ISO/IEC 5218 sex
769
     *
770
     * @API\Input(type="Sex")
771
     *
772
     * @param int $sex
773
     */
774
    public function setSex(int $sex): void
775
    {
776
        $this->sex = $sex;
777
    }
778
779
    /**
780
     * @return string
781
     */
782
    public function getIchtusSwissSailing(): string
783
    {
784
        return $this->ichtusSwissSailing;
785
    }
786
787
    /**
788
     * @param string $ichtusSwissSailing
789
     */
790
    public function setIchtusSwissSailing(string $ichtusSwissSailing): void
791
    {
792
        $this->ichtusSwissSailing = $ichtusSwissSailing;
793
    }
794
795
    /**
796
     * Get the last login
797
     *
798
     * @return null|Chronos
799
     */
800
    public function getLastLogin(): ?Chronos
801
    {
802
        return $this->lastLogin;
803
    }
804
805
    /**
806
     * @param null|Chronos $lastLogin
807
     */
808 3
    public function setLastLogin(?Chronos $lastLogin): void
809
    {
810 3
        $this->lastLogin = $lastLogin;
811 3
        $this->revokeToken();
812 3
    }
813
814
    /**
815
     * @API\Field(type="Relationship")
816
     *
817
     * @return string
818
     */
819 1
    public function getFamilyRelationship(): string
820
    {
821 1
        return $this->familyRelationship;
822
    }
823
824
    /**
825
     * @API\Input(type="Relationship")
826
     *
827
     * @param string $familyRelationship
828
     */
829
    public function setFamilyRelationship(string $familyRelationship): void
830
    {
831
        $this->familyRelationship = $familyRelationship;
832
    }
833
834
    /**
835
     * @return string
836
     */
837
    public function getBillingType(): string
838
    {
839
        return $this->billingType;
840
    }
841
842
    /**
843
     * @param string $billingType
844
     */
845
    public function setBillingType(string $billingType): void
846
    {
847
        $this->billingType = $billingType;
848
    }
849
850
    /**
851
     * Get the user transaction account
852
     *
853
     * @return null|Account
854
     */
855 1
    public function getAccount(): ?Account
856
    {
857 1
        return $this->accounts->count() ? $this->accounts->first() : null;
858
    }
859
860
    /**
861
     * Notify the user that it has a new account
862
     * This should only be called by Account::setOwner()
863
     *
864
     * @param Account $account
865
     */
866 1
    public function accountAdded(Account $account): void
867
    {
868 1
        $this->accounts->clear();
869 1
        $this->accounts->add($account);
870 1
    }
871
872
    /**
873
     * Notify the user that a account was removed
874
     * This should only be called by Account::setOwner()
875
     */
876 1
    public function accountRemoved(): void
877
    {
878 1
        $this->accounts->clear();
879 1
    }
880
881
    /**
882
     * Get messages sent to the user
883
     *
884
     * @return Collection
885
     */
886 1
    public function getMessages(): Collection
887
    {
888 1
        return $this->messages;
889
    }
890
891
    /**
892
     * Notify the user that it has a new message
893
     * This should only be called by Message::setRecipient()
894
     *
895
     * @param Message $message
896
     */
897 4
    public function messageAdded(Message $message): void
898
    {
899 4
        $this->messages->add($message);
900 4
    }
901
902
    /**
903
     * Notify the user that a message was removed
904
     * This should only be called by Message::setRecipient()
905
     *
906
     * @param Message $message
907
     */
908 1
    public function messageRemoved(Message $message): void
909
    {
910 1
        $this->messages->removeElement($message);
911 1
    }
912
913
    /**
914
     * Generate a new random token to reset password
915
     */
916 4
    public function createToken(): string
917
    {
918 4
        $this->token = bin2hex(random_bytes(16));
919 4
        $this->tokenCreationDate = new Chronos();
920
921 4
        return $this->token;
922
    }
923
924
    /**
925
     * Destroy existing token
926
     */
927 9
    private function revokeToken(): void
928
    {
929 9
        $this->token = null;
930 9
        $this->tokenCreationDate = null;
931 9
    }
932
933
    /**
934
     * Check if token is valid.
935
     *
936
     * @API\Exclude
937
     *
938
     * @return bool
939
     */
940 2
    public function isTokenValid(): bool
941
    {
942 2
        if (!$this->tokenCreationDate) {
943 1
            return false;
944
        }
945
946 2
        $timeLimit = $this->tokenCreationDate->addMinutes(30);
947
948 2
        return $timeLimit->isFuture();
949
    }
950
}
951