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

User   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 200
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 53
c 1
b 0
f 0
dl 0
loc 200
rs 9.84
wmc 32

30 Methods

Rating   Name   Duplication   Size   Complexity  
A markAsDeleted() 0 6 1
A getName() 0 3 1
A isConfirmed() 0 3 1
A setDeletedAt() 0 5 1
A getDeactivatedAt() 0 3 1
A isEqualTo() 0 7 2
A getDeletedAt() 0 3 1
A getUsername() 0 3 1
A getId() 0 3 1
A setIsConfirmed() 0 3 1
A getConfirmationCode() 0 3 1
A getPassword() 0 3 1
A setCreatedAt() 0 3 1
A setConfirmationCode() 0 3 1
A getRoles() 0 7 2
A setPassword() 0 3 1
A setDeactivatedAt() 0 3 1
A eraseCredentials() 0 3 1
A setName() 0 3 1
A getEmail() 0 3 1
A isDeleted() 0 3 1
A setRoles() 0 3 1
A getActivatedAt() 0 3 1
A setEmail() 0 3 1
A getSalt() 0 3 1
A setId() 0 3 1
A setActivatedAt() 0 3 1
A unmarkAsDeleted() 0 6 1
A getCreatedAt() 0 3 1
A getUserIdentifier() 0 3 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 Doctrine\Common\Collections\Collection;
18
use Parthenon\Athena\Entity\DeletableInterface;
19
use Symfony\Component\Security\Core\User\EquatableInterface;
20
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface;
21
use Symfony\Component\Validator\Constraints as Assert;
22
23
class User implements UserInterface, EquatableInterface, DeletableInterface
24
{
25
    public const DEFAULT_ROLE = 'ROLE_USER';
26
    protected $id;
27
    /**
28
     * @Assert\NotBlank(message="parthenon.user.validation.email.not_blank")
29
     * @Assert\Email(message="parthenon.user.validation.email.email")
30
     */
31
    protected string $email;
32
    /**
33
     * @Assert\NotBlank(message="parthenon.user.validation.password.not_blank")
34
     * @Assert\Length(min="8", minMessage="parthenon.user.validation.password.length")
35
     */
36
    protected string $password;
37
    protected ?string $name = null;
38
    protected string $confirmationCode;
39
    protected \DateTime $createdAt;
40
    protected ?\DateTime $activatedAt;
41
    protected ?\DateTime $deactivatedAt;
42
    protected ?\DateTimeInterface $deletedAt;
43
    protected bool $isConfirmed = false;
44
    protected $isDeleted = false;
45
    protected $roles = [];
46
47
    public function getId()
48
    {
49
        return $this->id;
50
    }
51
52
    public function setId($id): void
53
    {
54
        $this->id = $id;
55
    }
56
57
    public function getEmail(): string
58
    {
59
        return $this->email;
60
    }
61
62
    public function setEmail(string $email): void
63
    {
64
        $this->email = $email;
65
    }
66
67
    public function getPassword(): ?string
68
    {
69
        return $this->password;
70
    }
71
72
    public function setPassword(string $password): void
73
    {
74
        $this->password = $password;
75
    }
76
77
    public function setRoles(array $roles): void
78
    {
79
        $this->roles = $roles;
80
    }
81
82
    public function getRoles(): array
83
    {
84
        if ($this->roles instanceof Collection) {
0 ignored issues
show
introduced by
$this->roles is never a sub-type of Doctrine\Common\Collections\Collection.
Loading history...
85
            return $this->roles->toArray();
86
        }
87
88
        return $this->roles;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function getSalt()
95
    {
96
        return null;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function getUsername()
103
    {
104
        return $this->getEmail();
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function eraseCredentials()
111
    {
112
        $this->password = '';
113
    }
114
115
    public function getName(): ?string
116
    {
117
        return $this->name;
118
    }
119
120
    public function setName(?string $name): void
121
    {
122
        $this->name = $name;
123
    }
124
125
    public function getConfirmationCode(): string
126
    {
127
        return $this->confirmationCode;
128
    }
129
130
    public function setConfirmationCode(string $confirmationCode): void
131
    {
132
        $this->confirmationCode = $confirmationCode;
133
    }
134
135
    public function isConfirmed(): bool
136
    {
137
        return $this->isConfirmed;
138
    }
139
140
    public function setIsConfirmed(bool $isConfirmed): void
141
    {
142
        $this->isConfirmed = $isConfirmed;
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function isEqualTo(SymfonyUserInterface $user): bool
149
    {
150
        if ($this->getUsername() !== $user->getUsername()) {
0 ignored issues
show
Bug introduced by
The method getUsername() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as Parthenon\User\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

150
        if ($this->getUsername() !== $user->/** @scrutinizer ignore-call */ getUsername()) {
Loading history...
151
            return false;
152
        }
153
154
        return true;
155
    }
156
157
    public function getCreatedAt(): \DateTime
158
    {
159
        return $this->createdAt;
160
    }
161
162
    public function setCreatedAt(\DateTime $createdAt): void
163
    {
164
        $this->createdAt = $createdAt;
165
    }
166
167
    public function getActivatedAt(): ?\DateTime
168
    {
169
        return $this->activatedAt;
170
    }
171
172
    public function setActivatedAt(?\DateTime $activatedAt): void
173
    {
174
        $this->activatedAt = $activatedAt;
175
    }
176
177
    public function getDeactivatedAt(): ?\DateTime
178
    {
179
        return $this->deactivatedAt;
180
    }
181
182
    public function setDeactivatedAt(?\DateTime $deactivatedAt): void
183
    {
184
        $this->deactivatedAt = $deactivatedAt;
185
    }
186
187
    public function setDeletedAt(\DateTimeInterface $dateTime): DeletableInterface
188
    {
189
        $this->deletedAt = $dateTime;
190
191
        return $this;
192
    }
193
194
    public function getDeletedAt(): ?\DateTimeInterface
195
    {
196
        return $this->deletedAt;
197
    }
198
199
    public function isDeleted(): bool
200
    {
201
        return $this->isDeleted;
202
    }
203
204
    public function markAsDeleted(): self
205
    {
206
        $this->isDeleted = true;
207
        $this->deletedAt = new \DateTime('Now');
208
209
        return $this;
210
    }
211
212
    public function unmarkAsDeleted(): self
213
    {
214
        $this->isDeleted = false;
215
        $this->deletedAt = null;
216
217
        return $this;
218
    }
219
220
    public function getUserIdentifier(): string
221
    {
222
        return $this->email;
223
    }
224
}
225