99
1010namespace SymfonyCasts \Bundle \ResetPassword \Model ;
1111
12+ use SymfonyCasts \Bundle \ResetPassword \Exception \ResetPasswordRuntimeException ;
13+
1214/**
1315 * @author Jesse Rushlow <jr@rushlow.dev>
1416 * @author Ryan Weaver <ryan@symfonycasts.com>
@@ -52,11 +54,13 @@ public function __construct(string $token, \DateTimeInterface $expiresAt, ?int $
5254 * Internally, this consists of two parts - the selector and
5355 * the hashed token - but that's an implementation detail
5456 * of how the token will later be parsed.
57+ *
58+ * @throws ResetPasswordRuntimeException
5559 */
5660 public function getToken (): string
5761 {
5862 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. ' );
6064 }
6165
6266 return $ this ->token ;
@@ -85,7 +89,7 @@ public function getExpiresAt(): \DateTimeInterface
8589 *
8690 * symfony/translation is required to translate into a non-English locale.
8791 *
88- * @throws \LogicException
92+ * @throws ResetPasswordRuntimeException
8993 */
9094 public function getExpirationMessageKey (): string
9195 {
@@ -118,7 +122,7 @@ public function getExpirationMessageKey(): string
118122 /**
119123 * @return array<string, int>
120124 *
121- * @throws \LogicException
125+ * @throws ResetPasswordRuntimeException
122126 */
123127 public function getExpirationMessageData (): array
124128 {
@@ -130,9 +134,7 @@ public function getExpirationMessageData(): array
130134 /**
131135 * Get the interval that the token is valid for.
132136 *
133- * @throws \LogicException
134- *
135- * @psalm-suppress PossiblyFalseArgument
137+ * @throws ResetPasswordRuntimeException
136138 */
137139 public function getExpiresAtIntervalInstance (): \DateInterval
138140 {
@@ -142,6 +144,10 @@ public function getExpiresAtIntervalInstance(): \DateInterval
142144
143145 $ createdAtTime = \DateTimeImmutable::createFromFormat ('U ' , (string ) $ this ->generatedAt );
144146
147+ if (false === $ createdAtTime ) {
148+ throw new ResetPasswordRuntimeException (sprintf ('Unable to create DateTimeInterface instance from "generatedAt": %s ' , $ this ->generatedAt ));
149+ }
150+
145151 return $ this ->expiresAt ->diff ($ createdAtTime );
146152 }
147153
0 commit comments