Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ResetPasswordRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
19
100.00% covered (success)
100.00%
1 / 1
 setId
n/a
0 / 0
1
n/a
0 / 0
 getId
n/a
0 / 0
1
n/a
0 / 0
 setUserId
n/a
0 / 0
1
n/a
0 / 0
 getUserId
n/a
0 / 0
1
n/a
0 / 0
 setSelector
n/a
0 / 0
1
n/a
0 / 0
 getSelector
n/a
0 / 0
1
n/a
0 / 0
 setToken
n/a
0 / 0
1
n/a
0 / 0
 getToken
n/a
0 / 0
1
n/a
0 / 0
 setExpires
n/a
0 / 0
1
n/a
0 / 0
 getExpires
n/a
0 / 0
1
n/a
0 / 0
 setCreated
n/a
0 / 0
1
n/a
0 / 0
 getCreated
n/a
0 / 0
1
n/a
0 / 0
 __construct
n/a
0 / 0
1
n/a
0 / 0
 getUser
n/a
0 / 0
1
n/a
0 / 0
 getRequestedAt
n/a
0 / 0
1
n/a
0 / 0
 isExpired
n/a
0 / 0
1
n/a
0 / 0
 getExpiresAt
n/a
0 / 0
1
n/a
0 / 0
 getHashedToken
n/a
0 / 0
1
n/a
0 / 0
 schemaDef
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3namespace App\Entity;
4
5use App\Core\Entity;
6use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
7
8class ResetPasswordRequest extends Entity implements ResetPasswordRequestInterface
9{
10    // {{{ Autocode
11    // @codeCoverageIgnoreStart
12    private int $id;
13    private int $user_id;
14    private ?string $selector;
15    private ?string $token;
16    private \DateTimeInterface $expires;
17    private \DateTimeInterface $created;
18
19    public function setId(int $id): self
20    {
21        $this->id = $id;
22        return $this;
23    }
24
25    public function getId(): int
26    {
27        return $this->id;
28    }
29
30    public function setUserId(int $user_id): self
31    {
32        $this->user_id = $user_id;
33        return $this;
34    }
35
36    public function getUserId(): int
37    {
38        return $this->user_id;
39    }
40
41    public function setSelector(?string $selector): self
42    {
43        $this->selector = $selector;
44        return $this;
45    }
46
47    public function getSelector(): ?string
48    {
49        return $this->selector;
50    }
51
52    public function setToken(?string $token): self
53    {
54        $this->token = $token;
55        return $this;
56    }
57
58    public function getToken(): ?string
59    {
60        return $this->token;
61    }
62
63    public function setExpires(\DateTimeInterface $expires): self
64    {
65        $this->expires = $expires;
66        return $this;
67    }
68
69    public function getExpires(): \DateTimeInterface
70    {
71        return $this->expires;
72    }
73
74    public function setCreated(\DateTimeInterface $created): self
75    {
76        $this->created = $created;
77        return $this;
78    }
79
80    public function getCreated(): \DateTimeInterface
81    {
82        return $this->created;
83    }
84
85    // @codeCoverageIgnoreEnd
86    // }}} Autocode
87
88    // {{{ Interface
89    // @codeCoverageIgnoreStart
90    public function __construct(object $user, \DateTimeInterface $expiresAt, string $selector, string $hashedToken)
91    {
92        $this->user_id  = $user->getId();
93        $this->expires  = $expiresAt;
94        $this->selector = $selector;
95        $this->token    = $hashedToken;
96    }
97
98    public function getUser(): object
99    {
100        return LocalUser::getWithPK($this->user_id);
101    }
102
103    public function getRequestedAt(): \DateTimeInterface
104    {
105        return $this->created;
106    }
107
108    public function isExpired(): bool
109    {
110        return $this->expires->getTimestamp() <= time();
111    }
112
113    public function getExpiresAt(): \DateTimeInterface
114    {
115        return $this->expires;
116    }
117
118    public function getHashedToken(): string
119    {
120        return $this->token;
121    }
122    // @codeCoverageIgnoreEnd
123    // }}}
124
125    public static function schemaDef(): array
126    {
127        return [
128            'name'        => 'reset_password_request',
129            'description' => 'Represents a request made by a user to change their passowrd',
130            'fields'      => [
131                'id'       => ['type' => 'serial', 'not null' => true],
132                'user_id'  => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'many to many', 'not null' => true, 'description' => 'foreign key to local_user table'],
133                'selector' => ['type' => 'char', 'length' => 20],
134                'token'    => ['type' => 'char', 'length' => 100],
135                'expires'  => ['type' => 'datetime', 'not null' => true],
136                'created'  => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
137            ],
138            'primary key' => ['id'],
139        ];
140    }
141}