Skip to content

Commit 42e8b07

Browse files
author
Samuel Parkinson
committed
🐛 Fix errors in ArrayAdapter when the queue is empty.
1 parent 2f9ea48 commit 42e8b07

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Adapter/ArrayAdapter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class ArrayAdapter implements AdapterInterface
2424
/**
2525
* @param MessageInterface[]
2626
*/
27-
protected $queue;
27+
protected $queue = [];
2828

2929
/**
3030
* @param MessageInterface[] $messages
@@ -49,9 +49,15 @@ public function acknowledge(array $messages)
4949
*/
5050
public function dequeue(MessageFactoryInterface $factory, $limit)
5151
{
52-
$total = null === $limit ? count($this->queue) : $limit;
52+
/**
53+
* If {@see $limit} is null then {@see LimitIterator} should be passed -1 as the count
54+
* to avoid throwing OutOfBoundsException.
55+
*
56+
* @link https://github.com/php/php-src/blob/php-5.6.12/ext/spl/internal/limititerator.inc#L60-L62
57+
*/
58+
$count = (null === $limit) ? -1 : $limit;
5359

54-
return new LimitIterator(new ArrayIterator($this->queue), 0, $total);
60+
return new LimitIterator(new ArrayIterator($this->queue), 0, $count);
5561
}
5662

5763
/**

0 commit comments

Comments
 (0)