Passed
Push — main ( b87b9b...32046f )
by Axel
04:33
created

UserVerification::setCreatedDate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ZAuthBundle\Entity;
15
16
use DateTime;
17
use DateTimeInterface;
18
use Doctrine\DBAL\Types\Types;
19
use Doctrine\ORM\Mapping as ORM;
20
use Symfony\Component\Validator\Constraints as Assert;
21
use Zikula\ZAuthBundle\Repository\UserVerificationRepository;
22
23
/**
24
 * Account-change verification entity.
25
 * Holds a one-time use, expirable verification code used when a user needs to change his email address,
26
 * reset his password and has not answered any security questions,
27
 * or when a new user is registering with the site for the first time.
28
 */
29
#[ORM\Entity(repositoryClass: UserVerificationRepository::class)]
30
#[ORM\Table(name: 'users_verifychg')]
31
class UserVerification
32
{
33
    /**
34
     * ID: Primary ID of the verification record. Not related to the uid.
35
     */
36
    #[ORM\Id]
37
    #[ORM\Column]
38
    #[ORM\GeneratedValue(strategy: 'AUTO')]
39
    private int $id;
40
41
    /**
42
     * Change type: a code indicating what type of change action created this record.
43
     */
44
    #[ORM\Column(type: Types::SMALLINT)]
45
    private int $changetype;
46
47
    /**
48
     * User ID: Primary ID of the user record to which this verification record is related. Foreign key to users table.
49
     */
50
    #[ORM\Column]
51
    private int $uid;
52
53
    /**
54
     * New e-mail address: If the change type indicates that this verification record was created as a result of a user changing his e-mail address,
55
     * then this field holds the new address temporarily until the verification is complete.
56
     * Only after the verification code is received back from the user (thus, verifying the new e-mail address) is the new e-mail address saved to the user's account record.
57
     */
58
    #[ORM\Column(length: 60)]
59
    #[Assert\AtLeastOneOf([
60
        new Assert\Blank(),
61
        new Assert\Length(min: 1, max: 60)
62
    ])]
63
    private string $newemail;
64
65
    /**
66
     * Verification Code: The verification code last sent to the user to verify the requested action, as a salted hash of the value sent.
67
     */
68
    #[ORM\Column(length: 138)]
69
    #[Assert\AtLeastOneOf([
70
        new Assert\Blank(),
71
        new Assert\Length(min: 1, max: 138)
72
    ])]
73
    private string $verifycode;
74
75
    /**
76
     * Date/Time created: The date and time the verification record was created, as a UTC date/time, used to expire the record.
77
     */
78
    #[ORM\Column(name: 'created_dt', type: Types::DATETIME_MUTABLE)]
79
    private DateTimeInterface $createdDate;
80
81
    public function __construct()
82
    {
83
        $this->changetype = 0;
84
        $this->uid = 0;
85
        $this->newemail = '';
86
        $this->verifycode = '';
87
        $this->createdDate = new DateTime('now');
88
    }
89
90
    public function getId(): ?int
91
    {
92
        return $this->id;
93
    }
94
95
    public function setId(int $id): self
96
    {
97
        $this->id = $id;
98
99
        return $this;
100
    }
101
102
    public function getChangetype(): int
103
    {
104
        return $this->changetype;
105
    }
106
107
    public function setChangetype(int $changetype): self
108
    {
109
        $this->changetype = $changetype;
110
111
        return $this;
112
    }
113
114
    public function getUid(): int
115
    {
116
        return $this->uid;
117
    }
118
119
    public function setUid(int $uid): self
120
    {
121
        $this->uid = $uid;
122
123
        return $this;
124
    }
125
126
    public function getNewemail(): string
127
    {
128
        return $this->newemail;
129
    }
130
131
    public function setNewemail(string $newemail): self
132
    {
133
        $this->newemail = $newemail;
134
135
        return $this;
136
    }
137
138
    public function getVerifycode(): string
139
    {
140
        return $this->verifycode;
141
    }
142
143
    public function setVerifycode(string $verifycode): self
144
    {
145
        $this->verifycode = $verifycode;
146
147
        return $this;
148
    }
149
150
    public function getCreatedDate(): DateTimeInterface
151
    {
152
        return $this->createdDate;
153
    }
154
155
    public function setCreatedDate(string|DateTimeInterface $createdDate): self
156
    {
157
        if ($createdDate instanceof DateTimeInterface) {
158
            $this->createdDate = $createdDate;
159
        } else {
160
            $this->createdDate = new DateTime($createdDate);
161
        }
162
163
        return $this;
164
    }
165
}
166