Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] remove potential LogicException from translation methods #168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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