Skip to content

Commit

Permalink
feature #168 [2.x] remove potential LogicException from translation m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
jrushlow committed Mar 14, 2024
1 parent f9d57d3 commit 7ef1c50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
3 changes: 3 additions & 0 deletions UPGRADING.md
Expand Up @@ -14,3 +14,6 @@ when instantiating a new `VerifyEmailSignatureComponents` instance.
- public function __construct(\DateTimeInterface $expiresAt, string $uri, ?int $generatedAt = null)
+ public function __construct(\DateTimeInterface $expiresAt, string $uri, int $generatedAt)
```

- Method's `getExpirationMessageKey`, `getExpirationMessageData`, & `getExpiresAtIntervalInstance`
no longer potentially throw a `LogicException`.
13 changes: 1 addition & 12 deletions src/Model/VerifyEmailSignatureComponents.php
Expand Up @@ -26,7 +26,7 @@ final class VerifyEmailSignatureComponents
private $uri;

/**
* @var int|null timestamp when the signature was created
* @var int timestamp when the signature was created
*/
private $generatedAt;

Expand Down Expand Up @@ -67,8 +67,6 @@ public function getExpiresAt(): \DateTimeInterface
* <p>{{ components.expirationMessageKey|trans(components.expirationMessageData) }}</p>
*
* symfony/translation is required to translate into a non-English locale.
*
* @throws \LogicException
*/
public function getExpirationMessageKey(): string
{
Expand Down Expand Up @@ -98,9 +96,6 @@ public function getExpirationMessageKey(): string
}
}

/**
* @throws \LogicException
*/
public function getExpirationMessageData(): array
{
$this->getExpirationMessageKey();
Expand All @@ -111,16 +106,10 @@ public function getExpirationMessageData(): array
/**
* Get the interval that the signature is valid for.
*
* @throws \LogicException
*
* @psalm-suppress PossiblyFalseArgument
*/
public function getExpiresAtIntervalInstance(): \DateInterval
{
if (null === $this->generatedAt) {
throw new \LogicException(sprintf('%s initialized without setting the $generatedAt timestamp.', self::class));
}

$createdAtTime = \DateTimeImmutable::createFromFormat('U', (string) $this->generatedAt);

return $this->expiresAt->diff($createdAtTime);
Expand Down

0 comments on commit 7ef1c50

Please sign in to comment.