This commit is contained in:
Fabien Potencier 2020-08-17 08:12:26 +02:00
parent 66b9fef4ac
commit 3cdf5c47db
2 changed files with 7 additions and 7 deletions

View File

@ -79,24 +79,24 @@ class SendFailedMessageForRetryListener implements EventSubscriberInterface
}
/**
* Adds stamps to the envelope by keeping only the First + Last N stamps
* Adds stamps to the envelope by keeping only the First + Last N stamps.
*/
private function withLimitedHistory(Envelope $envelope, StampInterface ...$stamps): Envelope
{
foreach ($stamps as $stamp) {
$history = $envelope->all(get_class($stamp));
$history = $envelope->all(\get_class($stamp));
if (\count($history) < $this->historySize) {
$envelope = $envelope->with($stamp);
continue;
}
$history = \array_merge(
$history = array_merge(
[$history[0]],
\array_slice($history, -$this->historySize + 2),
[$stamp]
);
$envelope = $envelope->withoutAll(get_class($stamp))->with(...$history);
$envelope = $envelope->withoutAll(\get_class($stamp))->with(...$history);
}
return $envelope;

View File

@ -80,9 +80,9 @@ class SendFailedMessageForRetryListenerTest extends TestCase
public function testEnvelopeKeepOnlyTheLast10Stamps()
{
$exception = new \Exception('no!');
$stamps = \array_merge(
\array_fill(0, 15, new DelayStamp(1)),
\array_fill(0, 3, new RedeliveryStamp(1))
$stamps = array_merge(
array_fill(0, 15, new DelayStamp(1)),
array_fill(0, 3, new RedeliveryStamp(1))
);
$envelope = new Envelope(new \stdClass(), $stamps);