8000 [Messenger] Fix deprecation layer of RedeliveryStamp · symfony/symfony@8b4740d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b4740d

Browse files
[Messenger] Fix deprecation layer of RedeliveryStamp
1 parent 5ba3046 commit 8b4740d

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,19 @@ final class RedeliveryStamp implements StampInterface
2525
private $flattenException;
2626

2727
/**
28-
* @param \DateTimeInterface|null $exceptionMessage
28+
* @param \DateTimeInterface|null $redeliveredAt
2929
*/
30-
public function __construct(int $retryCount, $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
30+
public function __construct(int $retryCount, $redeliveredAt = null)
3131
{
32-
$this->retryCount = $retryCount;
33-
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
34-
if (null !== $redeliveredAt) {
35-
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));
36-
}
37-
38-
if ($exceptionMessage instanceof \DateTimeInterface) {
39-
// In Symfony 6.0, the second argument will be $redeliveredAt
40-
$this->redeliveredAt = $exceptionMessage;
41-
if (null !== $redeliveredAt) {
42-
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.');
43-
}
44-
} elseif (null !== $exceptionMessage) {
45-
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));
46-
$this->exceptionMessage = $exceptionMessage;
32+
if (2 < \func_num_args() || null !== $redeliveredAt && !$redeliveredAt instanceof \DateTimeInterface) {
33+
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));
34+
$this->exceptionMessage = $redeliveredAt instanceof \DateTimeInterface ? null : $redeliveredAt;
35+
$redeliveredAt = 4 <= \func_num_args() ? func_get_arg(3) : ($redeliveredAt instanceof \DateTimeInterface ? $redeliveredAt : null);
36+
$this->flattenException = 3 <= \func_num_args() ? func_get_arg(2) : null;
4737
}
4838

49-
if (null !== $flattenException) {
50-
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));
51-
}
52-
$this->flattenException = $flattenException;
39+
$this->retryCount = $retryCount;
40+
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
5341
}
5442

5543
public static function getRetryCountFromEnvelope(Envelope $envelope): int

src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,9 @@ public function testRedeliveryAt()
4444
*/
4545
public function testLegacyRedeliveryAt()
4646
{
47-
$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.');
47+
$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.');
4848
$redeliveredAt = new \DateTimeImmutable('+2minutes');
4949
$stamp = new RedeliveryStamp(10, null, null, $redeliveredAt);
5050
$this->assertSame($redeliveredAt, $stamp->getRedeliveredAt());
5151
}
52-
53-
/**
54-
* @group legacy
55-
*/
56-
public function testPassingBothLegacyAndCurrentRedeliveryAt()
57-
{
58-
$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.');
59-
$redeliveredAt = new \DateTimeImmutable('+2minutes');
60-
$this->expectException(\LogicException::class);
61-
new RedeliveryStamp(10, $redeliveredAt, null, $redeliveredAt);
62-
}
6352
}

0 commit comments

Comments
 (0)
0