Skip to content

Commit

Permalink
🐛 Fix errors in ArrayAdapter when the queue is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Parkinson committed Aug 21, 2015
1 parent 2f9ea48 commit 42e8b07
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ArrayAdapter implements AdapterInterface
/**
* @param MessageInterface[]
*/
protected $queue;
protected $queue = [];

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

return new LimitIterator(new ArrayIterator($this->queue), 0, $total);
return new LimitIterator(new ArrayIterator($this->queue), 0, $count);
}

/**
Expand Down

0 comments on commit 42e8b07

Please sign in to comment.