Skip to content

[Messenger] Fix deprecation layer of RedeliveryStamp #50049

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

Merged
merged 1 commit into from
Apr 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,19 @@ final class RedeliveryStamp implements StampInterface
private $flattenException;

/**
* @param \DateTimeInterface|null $exceptionMessage
* @param \DateTimeInterface|null $redeliveredAt
*/
public function __construct(int $retryCount, $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
public function __construct(int $retryCount, $redeliveredAt = null)
{
$this->retryCount = $retryCount;
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
if (null !== $redeliveredAt) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$redeliveredAt" as 4th argument of the "%s::__construct()" is deprecated, pass "$redeliveredAt" as second argument instead.', self::class));
}

if ($exceptionMessage instanceof \DateTimeInterface) {
// In Symfony 6.0, the second argument will be $redeliveredAt
$this->redeliveredAt = $exceptionMessage;
if (null !== $redeliveredAt) {
throw new \LogicException('It is deprecated to specify a redeliveredAt as 4th argument. The correct way is to specify redeliveredAt as the second argument. Using both is not allowed.');
}
} elseif (null !== $exceptionMessage) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$exceptionMessage" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
$this->exceptionMessage = $exceptionMessage;
if (2 < \func_num_args() || null !== $redeliveredAt && !$redeliveredAt instanceof \DateTimeInterface) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using parameters "$exceptionMessage" or "$flattenException" of class "%s" is deprecated, use "%s" instead and/or pass "$redeliveredAt" as parameter #2.', self::class, ErrorDetailsStamp::class));
$this->exceptionMessage = $redeliveredAt instanceof \DateTimeInterface ? null : $redeliveredAt;
$redeliveredAt = 4 <= \func_num_args() ? func_get_arg(3) : ($redeliveredAt instanceof \DateTimeInterface ? $redeliveredAt : null);
$this->flattenException = 3 <= \func_num_args() ? func_get_arg(2) : null;
}

if (null !== $flattenException) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$flattenException" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
}
$this->flattenException = $flattenException;
$this->retryCount = $retryCount;
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
}

public static function getRetryCountFromEnvelope(Envelope $envelope): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,9 @@ public function testRedeliveryAt()
*/
public function testLegacyRedeliveryAt()
{
$this->expectDeprecation('Since symfony/messenger 5.2: Using the "$redeliveredAt" as 4th argument of the "Symfony\Component\Messenger\Stamp\RedeliveryStamp::__construct()" is deprecated, pass "$redeliveredAt" as second argument instead.');
$this->expectDeprecation('Since symfony/messenger 5.2: Using parameters "$exceptionMessage" or "$flattenException" of class "Symfony\Component\Messenger\Stamp\RedeliveryStamp" is deprecated, use "Symfony\Component\Messenger\Stamp\ErrorDetailsStamp" instead and/or pass "$redeliveredAt" as parameter #2.');
$redeliveredAt = new \DateTimeImmutable('+2minutes');
$stamp = new RedeliveryStamp(10, null, null, $redeliveredAt);
$this->assertSame($redeliveredAt, $stamp->getRedeliveredAt());
}

/**
* @group legacy
*/
public function testPassingBothLegacyAndCurrentRedeliveryAt()
{
$this->expectDeprecation('Since symfony/messenger 5.2: Using the "$redeliveredAt" as 4th argument of the "Symfony\Component\Messenger\Stamp\RedeliveryStamp::__construct()" is deprecated, pass "$redeliveredAt" as second argument instead.');
$redeliveredAt = new \DateTimeImmutable('+2minutes');
$this->expectException(\LogicException::class);
new RedeliveryStamp(10, $redeliveredAt, null, $redeliveredAt);
}
}