Passed
Push — main ( 8e7dcd...c22011 )
by Iain
04:36
created

InviteCode::setRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
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.2.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
    protected ?string $role = null;
33
34
    public function getId()
35
    {
36
        return $this->id;
37
    }
38
39
    public function setId($id): self
40
    {
41
        $this->id = $id;
42
43
        return $this;
44
    }
45
46
    public function getUser(): UserInterface
47
    {
48
        return $this->user;
49
    }
50
51
    public function setUser(UserInterface $user): self
52
    {
53
        $this->user = $user;
54
55
        return $this;
56
    }
57
58
    public function isUsed(): bool
59
    {
60
        return $this->used;
61
    }
62
63
    public function setUsed(bool $used): self
64
    {
65
        $this->used = $used;
66
67
        return $this;
68
    }
69
70
    public function getCreatedAt(): DateTime
71
    {
72
        return $this->createdAt;
73
    }
74
75
    public function setCreatedAt(DateTime $createdAt): self
76
    {
77
        $this->createdAt = $createdAt;
78
79
        return $this;
80
    }
81
82
    public function getUsedAt(): ?DateTime
83
    {
84
        return $this->usedAt;
85
    }
86
87
    public function setUsedAt(?DateTime $usedAt): self
88
    {
89
        $this->usedAt = $usedAt;
90
91
        return $this;
92
    }
93
94
    public function getCode(): string
95
    {
96
        return $this->code;
97
    }
98
99
    public function setCode(string $code): self
100
    {
101
        $this->code = $code;
102
103
        return $this;
104
    }
105
106
    public function getEmail(): string
107
    {
108
        return $this->email;
109
    }
110
111
    public function setEmail(string $email): self
112
    {
113
        $this->email = $email;
114
115
        return $this;
116
    }
117
118
    public function getInvitedUser(): ?UserInterface
119
    {
120
        return $this->invitedUser;
121
    }
122
123
    public function setInvitedUser(?UserInterface $invitedUser): self
124
    {
125
        $this->invitedUser = $invitedUser;
126
127
        return $this;
128
    }
129
130
    public function isCancelled(): bool
131
    {
132
        return $this->cancelled;
133
    }
134
135
    public function setCancelled(bool $cancelled): void
136
    {
137
        $this->cancelled = $cancelled;
138
    }
139
140
    public static function createForUser(UserInterface $user, string $email, ?string $role = null): self
141
    {
142
        $self = new static();
143
        $self->setUser($user)
144
            ->setEmail($email)
145
            ->setRole($role)
146
            ->setCode(bin2hex(random_bytes(32)))
147
            ->setUsed(false)
148
            ->setCreatedAt(new \DateTime('now'));
149
150
        return $self;
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getRole(): ?string
157
    {
158
        return $this->role;
159
    }
160
161
    public function setRole(?string $role): static
162
    {
163
        $this->role = $role;
164
165
        return $this;
166
    }
167
}
168