Passed
Branch main (b6a268)
by Iain
04:11
created

InviteCode   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
c 1
b 0
f 0
dl 0
loc 130
rs 10
wmc 19

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getInvitedUser() 0 3 1
A getCreatedAt() 0 3 1
A setInvitedUser() 0 5 1
A setUser() 0 5 1
A setCancelled() 0 3 1
A createForUser() 0 10 1
A setCreatedAt() 0 5 1
A getId() 0 3 1
A getUsedAt() 0 3 1
A setEmail() 0 5 1
A setUsed() 0 5 1
A getEmail() 0 3 1
A setId() 0 5 1
A isCancelled() 0 3 1
A setCode() 0 5 1
A getCode() 0 3 1
A isUsed() 0 3 1
A getUser() 0 3 1
A setUsedAt() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Ltd 2020-2022.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.0.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\User\Entity;
16
17
use DateTime;
18
19
class InviteCode
20
{
21
    public const AUTH_CHECKER_ATTRIBUTE = 'enable';
22
23
    protected $id;
24
    protected UserInterface $user;
25
    protected ?UserInterface $invitedUser;
26
    protected string $code;
27
    protected string $email;
28
    protected bool $used;
29
    protected DateTime $createdAt;
30
    protected ?DateTime $usedAt;
31
    protected bool $cancelled = false;
32
33
    public function getId()
34
    {
35
        return $this->id;
36
    }
37
38
    public function setId($id): self
39
    {
40
        $this->id = $id;
41
42
        return $this;
43
    }
44
45
    public function getUser(): UserInterface
46
    {
47
        return $this->user;
48
    }
49
50
    public function setUser(UserInterface $user): self
51
    {
52
        $this->user = $user;
53
54
        return $this;
55
    }
56
57
    public function isUsed(): bool
58
    {
59
        return $this->used;
60
    }
61
62
    public function setUsed(bool $used): self
63
    {
64
        $this->used = $used;
65
66
        return $this;
67
    }
68
69
    public function getCreatedAt(): DateTime
70
    {
71
        return $this->createdAt;
72
    }
73
74
    public function setCreatedAt(DateTime $createdAt): self
75
    {
76
        $this->createdAt = $createdAt;
77
78
        return $this;
79
    }
80
81
    public function getUsedAt(): ?DateTime
82
    {
83
        return $this->usedAt;
84
    }
85
86
    public function setUsedAt(?DateTime $usedAt): self
87
    {
88
        $this->usedAt = $usedAt;
89
90
        return $this;
91
    }
92
93
    public function getCode(): string
94
    {
95
        return $this->code;
96
    }
97
98
    public function setCode(string $code): self
99
    {
100
        $this->code = $code;
101
102
        return $this;
103
    }
104
105
    public function getEmail(): string
106
    {
107
        return $this->email;
108
    }
109
110
    public function setEmail(string $email): self
111
    {
112
        $this->email = $email;
113
114
        return $this;
115
    }
116
117
    public function getInvitedUser(): ?UserInterface
118
    {
119
        return $this->invitedUser;
120
    }
121
122
    public function setInvitedUser(?UserInterface $invitedUser): self
123
    {
124
        $this->invitedUser = $invitedUser;
125
126
        return $this;
127
    }
128
129
    public function isCancelled(): bool
130
    {
131
        return $this->cancelled;
132
    }
133
134
    public function setCancelled(bool $cancelled): void
135
    {
136
        $this->cancelled = $cancelled;
137
    }
138
139
    public static function createForUser(UserInterface $user, string $email): self
140
    {
141
        $self = new static();
142
        $self->setUser($user)
143
            ->setEmail($email)
144
            ->setCode(bin2hex(random_bytes(32)))
145
            ->setUsed(false)
146
            ->setCreatedAt(new \DateTime('now'));
147
148
        return $self;
149
    }
150
}
151