diff options
author | Mario <mario@mariovavti.com> | 2021-02-15 18:29:24 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-02-15 18:29:24 +0000 |
commit | 02401ea9fd5d53f590305c0f9834685cda58723d (patch) | |
tree | e60e292f8ae389c3a353dafda37003b4c15a45d5 /vendor/ramsey/collection/src/Queue.php | |
parent | 18c8f1b903e90ca3632520b90d21ec3770bf6e0b (diff) | |
download | volse-hubzilla-02401ea9fd5d53f590305c0f9834685cda58723d.tar.gz volse-hubzilla-02401ea9fd5d53f590305c0f9834685cda58723d.tar.bz2 volse-hubzilla-02401ea9fd5d53f590305c0f9834685cda58723d.zip |
composer update ramsey/collection
Diffstat (limited to 'vendor/ramsey/collection/src/Queue.php')
-rw-r--r-- | vendor/ramsey/collection/src/Queue.php | 95 |
1 files changed, 19 insertions, 76 deletions
diff --git a/vendor/ramsey/collection/src/Queue.php b/vendor/ramsey/collection/src/Queue.php index 4f53ff5e6..4af2fdf76 100644 --- a/vendor/ramsey/collection/src/Queue.php +++ b/vendor/ramsey/collection/src/Queue.php @@ -22,6 +22,10 @@ use Ramsey\Collection\Tool\ValueToStringTrait; /** * This class provides a basic implementation of `QueueInterface`, to minimize * the effort required to implement this interface. + * + * @template T + * @template-extends AbstractArray<T> + * @template-implements QueueInterface<T> */ class Queue extends AbstractArray implements QueueInterface { @@ -50,7 +54,7 @@ class Queue extends AbstractArray implements QueueInterface * specified data. * * @param string $queueType The type (FQCN) associated with this queue. - * @param mixed[] $data The initial items to store in the collection. + * @param array<array-key, T> $data The initial items to store in the collection. */ public function __construct(string $queueType, array $data = []) { @@ -59,19 +63,11 @@ class Queue extends AbstractArray implements QueueInterface } /** - * Sets the given value to the given offset in the queue. + * {@inheritDoc} * * Since arbitrary offsets may not be manipulated in a queue, this method * serves only to fulfill the `ArrayAccess` interface requirements. It is * invoked by other operations when adding values to the queue. - * - * @link http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet() - * - * @param mixed|null $offset The offset is ignored and is treated as `null`. - * @param mixed $value The value to set at the given offset. - * - * @throws InvalidArgumentException when the value does not match the - * specified type for this queue. */ public function offsetSet($offset, $value): void { @@ -86,19 +82,7 @@ class Queue extends AbstractArray implements QueueInterface } /** - * Ensures that this queue contains the specified element. - * - * This method differs from `offer()` only in that it throws an exception if - * it cannot add the element to the queue. - * - * @see self::offer() - * - * @param mixed $element The element to add to this queue. - * - * @return bool `true` if this queue changed as a result of the call. - * - * @throws InvalidArgumentException when the element does not match the - * specified type for this queue. + * @inheritDoc */ public function add($element): bool { @@ -108,39 +92,23 @@ class Queue extends AbstractArray implements QueueInterface } /** - * Retrieves, but does not remove, the head of this queue. - * - * This method differs from `peek()` only in that it throws an exception if - * this queue is empty. - * - * @see self::peek() - * - * @return mixed the head of this queue. - * - * @throws NoSuchElementException if this queue is empty. + * @inheritDoc */ public function element() { - if ($this->count() === 0) { + $element = $this->peek(); + + if ($element === null) { throw new NoSuchElementException( 'Can\'t return element from Queue. Queue is empty.' ); } - return $this[$this->index]; + return $element; } /** - * Inserts the specified element into this queue. - * - * This method differs from `add()` only in that it does not throw an - * exception if it cannot add the element to the queue. - * - * @see self::add() - * - * @param mixed $element The element to add to this queue. - * - * @return bool `true` if the element was added to this queue, else `false`. + * @inheritDoc */ public function offer($element): bool { @@ -152,12 +120,7 @@ class Queue extends AbstractArray implements QueueInterface } /** - * Retrieves, but does not remove, the head of this queue, or returns `null` - * if this queue is empty. - * - * @see self::element() - * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @inheritDoc */ public function peek() { @@ -169,12 +132,7 @@ class Queue extends AbstractArray implements QueueInterface } /** - * Retrieves and removes the head of this queue, or returns `null` - * if this queue is empty. - * - * @see self::remove() - * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @inheritDoc */ public function poll() { @@ -191,34 +149,19 @@ class Queue extends AbstractArray implements QueueInterface } /** - * Retrieves and removes the head of this queue. - * - * This method differs from `poll()` only in that it throws an exception if - * this queue is empty. - * - * @see self::poll() - * - * @return mixed the head of this queue. - * - * @throws NoSuchElementException if this queue is empty. + * @inheritDoc */ public function remove() { - if ($this->count() === 0) { + $head = $this->poll(); + + if ($head === null) { throw new NoSuchElementException('Can\'t return element from Queue. Queue is empty.'); } - $head = $this[$this->index]; - - unset($this[$this->index]); - $this->index++; - return $head; } - /** - * Returns the type associated with this queue. - */ public function getType(): string { return $this->queueType; |