9
9
10
10
namespace SymfonyCasts \Bundle \ResetPassword \Model ;
11
11
12
+ use SymfonyCasts \Bundle \ResetPassword \Exception \ResetPasswordRuntimeException ;
13
+
12
14
/**
13
15
* @author Jesse Rushlow <jr@rushlow.dev>
14
16
* @author Ryan Weaver <ryan@symfonycasts.com>
@@ -52,11 +54,13 @@ public function __construct(string $token, \DateTimeInterface $expiresAt, ?int $
52
54
* Internally, this consists of two parts - the selector and
53
55
* the hashed token - but that's an implementation detail
54
56
* of how the token will later be parsed.
57
+ *
58
+ * @throws ResetPasswordRuntimeException
55
59
*/
56
60
public function getToken (): string
57
61
{
58
62
if (null === $ this ->token ) {
59
- throw new \ RuntimeException ('The token property is not set. Calling getToken() after calling clearToken() is not allowed. ' );
63
+ throw new ResetPasswordRuntimeException ('The token property is not set. Calling getToken() after calling clearToken() is not allowed. ' );
60
64
}
61
65
62
66
return $ this ->token ;
@@ -85,7 +89,7 @@ public function getExpiresAt(): \DateTimeInterface
85
89
*
86
90
* symfony/translation is required to translate into a non-English locale.
87
91
*
88
- * @throws \LogicException
92
+ * @throws ResetPasswordRuntimeException
89
93
*/
90
94
public function getExpirationMessageKey (): string
91
95
{
@@ -118,7 +122,7 @@ public function getExpirationMessageKey(): string
118
122
/**
119
123
* @return array<string, int>
120
124
*
121
- * @throws \LogicException
125
+ * @throws ResetPasswordRuntimeException
122
126
*/
123
127
public function getExpirationMessageData (): array
124
128
{
@@ -130,9 +134,7 @@ public function getExpirationMessageData(): array
130
134
/**
131
135
* Get the interval that the token is valid for.
132
136
*
133
- * @throws \LogicException
134
- *
135
- * @psalm-suppress PossiblyFalseArgument
137
+ * @throws ResetPasswordRuntimeException
136
138
*/
137
139
public function getExpiresAtIntervalInstance (): \DateInterval
138
140
{
@@ -142,6 +144,10 @@ public function getExpiresAtIntervalInstance(): \DateInterval
142
144
143
145
$ createdAtTime = \DateTimeImmutable::createFromFormat ('U ' , (string ) $ this ->generatedAt );
144
146
147
+ if (false === $ createdAtTime ) {
148
+ throw new ResetPasswordRuntimeException (sprintf ('Unable to create DateTimeInterface instance from "generatedAt": %s ' , $ this ->generatedAt ));
149
+ }
150
+
145
151
return $ this ->expiresAt ->diff ($ createdAtTime );
146
152
}
147
153
0 commit comments