diff options
author | Hilmar R <u02@u29lx193> | 2021-02-28 21:06:16 +0100 |
---|---|---|
committer | Hilmar R <u02@u29lx193> | 2021-03-01 18:48:11 +0100 |
commit | c26dede97f626b52b7bf8962ed55d1dbda86abe8 (patch) | |
tree | 3c8c9bc97aa09f7ce9afe9bf467cf87bbf2c7d0b /vendor/ramsey/collection/src | |
parent | ea3390d626f85b7293a750958bfd1b5460958365 (diff) | |
download | volse-hubzilla-c26dede97f626b52b7bf8962ed55d1dbda86abe8.tar.gz volse-hubzilla-c26dede97f626b52b7bf8962ed55d1dbda86abe8.tar.bz2 volse-hubzilla-c26dede97f626b52b7bf8962ed55d1dbda86abe8.zip |
get dev
Diffstat (limited to 'vendor/ramsey/collection/src')
21 files changed, 332 insertions, 599 deletions
diff --git a/vendor/ramsey/collection/src/AbstractArray.php b/vendor/ramsey/collection/src/AbstractArray.php index f8b4be2ce..2c6e0dedd 100644 --- a/vendor/ramsey/collection/src/AbstractArray.php +++ b/vendor/ramsey/collection/src/AbstractArray.php @@ -23,20 +23,23 @@ use function unserialize; /** * This class provides a basic implementation of `ArrayInterface`, to minimize * the effort required to implement this interface. + * + * @template T + * @template-implements ArrayInterface<T> */ abstract class AbstractArray implements ArrayInterface { /** * The items of this array. * - * @var mixed[] + * @var array<array-key, T> */ protected $data = []; /** * Constructs a new array object. * - * @param mixed[] $data The initial items to add to this array. + * @param array<array-key, T> $data The initial items to add to this array. */ public function __construct(array $data = []) { @@ -51,8 +54,6 @@ abstract class AbstractArray implements ArrayInterface * Returns an iterator for this array. * * @link http://php.net/manual/en/iteratoraggregate.getiterator.php IteratorAggregate::getIterator() - * - * @return ArrayIterator<mixed, mixed> */ public function getIterator(): Traversable { @@ -64,7 +65,7 @@ abstract class AbstractArray implements ArrayInterface * * @link http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists() * - * @param mixed $offset The offset to check. + * @param array-key $offset The offset to check. */ public function offsetExists($offset): bool { @@ -76,9 +77,9 @@ abstract class AbstractArray implements ArrayInterface * * @link http://php.net/manual/en/arrayaccess.offsetget.php ArrayAccess::offsetGet() * - * @param mixed $offset The offset for which a value should be returned. + * @param array-key $offset The offset for which a value should be returned. * - * @return mixed|null the value stored at the offset, or null if the offset + * @return T|null the value stored at the offset, or null if the offset * does not exist. */ public function offsetGet($offset) @@ -91,10 +92,11 @@ abstract class AbstractArray implements ArrayInterface * * @link http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet() * - * @param mixed|null $offset The offset to set. If `null`, the value may be + * @param array-key|null $offset The offset to set. If `null`, the value may be * set at a numerically-indexed offset. - * @param mixed $value The value to set at the given offset. + * @param T $value The value to set at the given offset. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function offsetSet($offset, $value): void { if ($offset === null) { @@ -109,7 +111,7 @@ abstract class AbstractArray implements ArrayInterface * * @link http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset() * - * @param mixed $offset The offset to remove from the array. + * @param array-key $offset The offset to remove from the array. */ public function offsetUnset($offset): void { @@ -139,7 +141,10 @@ abstract class AbstractArray implements ArrayInterface */ public function unserialize($serialized): void { - $this->data = unserialize($serialized, ['allowed_classes' => false]); + /** @var array<array-key, T> $data */ + $data = unserialize($serialized, ['allowed_classes' => false]); + + $this->data = $data; } /** @@ -152,27 +157,19 @@ abstract class AbstractArray implements ArrayInterface return count($this->data); } - /** - * Removes all items from this array. - */ public function clear(): void { $this->data = []; } /** - * Returns a native PHP array representation of this array object. - * - * @return mixed[] + * @inheritDoc */ public function toArray(): array { return $this->data; } - /** - * Returns `true` if this array is empty. - */ public function isEmpty(): bool { return count($this->data) === 0; diff --git a/vendor/ramsey/collection/src/AbstractCollection.php b/vendor/ramsey/collection/src/AbstractCollection.php index 546f1adba..2facf0e89 100644 --- a/vendor/ramsey/collection/src/AbstractCollection.php +++ b/vendor/ramsey/collection/src/AbstractCollection.php @@ -14,11 +14,11 @@ declare(strict_types=1); namespace Ramsey\Collection; +use Closure; use Ramsey\Collection\Exception\CollectionMismatchException; use Ramsey\Collection\Exception\InvalidArgumentException; use Ramsey\Collection\Exception\InvalidSortOrderException; use Ramsey\Collection\Exception\OutOfBoundsException; -use Ramsey\Collection\Exception\ValueExtractionException; use Ramsey\Collection\Tool\TypeTrait; use Ramsey\Collection\Tool\ValueExtractorTrait; use Ramsey\Collection\Tool\ValueToStringTrait; @@ -40,6 +40,10 @@ use function usort; /** * This class provides a basic implementation of `CollectionInterface`, to * minimize the effort required to implement this interface + * + * @template T + * @template-extends AbstractArray<T> + * @template-implements CollectionInterface<T> */ abstract class AbstractCollection extends AbstractArray implements CollectionInterface { @@ -48,14 +52,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt use ValueExtractorTrait; /** - * Ensures that this collection contains the specified element. - * - * @param mixed $element The element to add to the collection. - * - * @return bool `true` if this collection changed as a result of the call. - * - * @throws InvalidArgumentException when the element does not match the - * specified type for this collection. + * @inheritDoc */ public function add($element): bool { @@ -65,10 +62,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt } /** - * Returns `true` if this collection contains the specified element. - * - * @param mixed $element The element to check whether the collection contains. - * @param bool $strict Whether to perform a strict type check on the value. + * @inheritDoc */ public function contains($element, bool $strict = true): bool { @@ -76,14 +70,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt } /** - * Sets the given value to the given offset in the array. - * - * @param mixed|null $offset The position to set the value in the array, or - * `null` to append the value to the array. - * @param mixed $value The value to set at the given offset. - * - * @throws InvalidArgumentException when the value does not match the - * specified type for this collection. + * @inheritDoc */ public function offsetSet($offset, $value): void { @@ -102,12 +89,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt } /** - * Removes a single instance of the specified element from this collection, - * if it is present. - * - * @param mixed $element The element to remove from the collection. - * - * @return bool `true` if an element was removed as a result of this call. + * @inheritDoc */ public function remove($element): bool { @@ -121,31 +103,25 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt } /** - * Returns the values from given property or method. - * - * @param string $propertyOrMethod The property or method name to filter by. - * - * @return mixed[] - * - * @throws ValueExtractionException if property or method is not defined. + * @inheritDoc */ public function column(string $propertyOrMethod): array { $temp = []; foreach ($this->data as $item) { - $temp[] = $this->extractValue($item, $propertyOrMethod); + /** @var mixed $value */ + $value = $this->extractValue($item, $propertyOrMethod); + + /** @psalm-suppress MixedAssignment */ + $temp[] = $value; } return $temp; } /** - * Returns the first item of the collection. - * - * @return mixed - * - * @throws OutOfBoundsException when the collection is empty. + * @inheritDoc */ public function first() { @@ -155,15 +131,14 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt reset($this->data); - return current($this->data); + /** @var T $first */ + $first = current($this->data); + + return $first; } /** - * Returns the last item of the collection. - * - * @return mixed - * - * @throws OutOfBoundsException when the collection is empty. + * @inheritDoc */ public function last() { @@ -171,27 +146,13 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt throw new OutOfBoundsException('Can\'t determine last item. Collection is empty'); } + /** @var T $item */ $item = end($this->data); reset($this->data); return $item; } - /** - * Returns a sorted collection. - * - * {@inheritdoc} - * - * @param string $propertyOrMethod The property or method to sort by. - * @param string $order The sort order for the resulting collection (one of - * this interface's `SORT_*` constants). - * - * @return CollectionInterface<mixed, mixed> - * - * @throws InvalidSortOrderException if neither "asc" nor "desc" was given - * as the order. - * @throws ValueExtractionException if property or method is not defined. - */ public function sort(string $propertyOrMethod, string $order = self::SORT_ASC): CollectionInterface { if (!in_array($order, [self::SORT_ASC, self::SORT_DESC], true)) { @@ -200,25 +161,26 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt $collection = clone $this; - usort($collection->data, function ($a, $b) use ($propertyOrMethod, $order) { - $aValue = $this->extractValue($a, $propertyOrMethod); - $bValue = $this->extractValue($b, $propertyOrMethod); + usort( + $collection->data, + /** + * @param T $a + * @param T $b + */ + function ($a, $b) use ($propertyOrMethod, $order): int { + /** @var mixed $aValue */ + $aValue = $this->extractValue($a, $propertyOrMethod); - return ($aValue <=> $bValue) * ($order === self::SORT_DESC ? -1 : 1); - }); + /** @var mixed $bValue */ + $bValue = $this->extractValue($b, $propertyOrMethod); + + return ($aValue <=> $bValue) * ($order === self::SORT_DESC ? -1 : 1); + } + ); return $collection; } - /** - * Returns a filtered collection. - * - * {@inheritdoc} - * - * @param callable $callback A callable to use for filtering elements. - * - * @return CollectionInterface<mixed, mixed> - */ public function filter(callable $callback): CollectionInterface { $collection = clone $this; @@ -228,84 +190,31 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt } /** - * Returns a collection of matching items. - * * {@inheritdoc} - * - * @param string $propertyOrMethod The property or method to evaluate. - * @param mixed $value The value to match. - * - * @return CollectionInterface<mixed, mixed> - * - * @throws ValueExtractionException if property or method is not defined. */ public function where(string $propertyOrMethod, $value): CollectionInterface { return $this->filter(function ($item) use ($propertyOrMethod, $value) { + /** @var mixed $accessorValue */ $accessorValue = $this->extractValue($item, $propertyOrMethod); return $accessorValue === $value; }); } - /** - * Applies a callback to each item of the collection. - * - * {@inheritdoc} - * - * @param callable $callback A callable to apply to each item of the - * collection. - * - * @return CollectionInterface<mixed, mixed> - */ public function map(callable $callback): CollectionInterface { - $collection = clone $this; - $collection->data = array_map($callback, $collection->data); - - return $collection; + return new Collection('mixed', array_map($callback, $this->data)); } - /** - * Create a new collection with divergent items between current and given - * collection. - * - * @param CollectionInterface<mixed, mixed> $other The collection to check for divergent - * items. - * - * @return CollectionInterface<mixed, mixed> - * - * @throws CollectionMismatchException if the given collection is not of the - * same type. - */ public function diff(CollectionInterface $other): CollectionInterface { - if (!$other instanceof static) { - throw new CollectionMismatchException('Collection must be of type ' . static::class); - } - - // When using generics (Collection.php, Set.php, etc), - // we also need to make sure that the internal types match each other - if ($other->getType() !== $this->getType()) { - throw new CollectionMismatchException('Collection items must be of type ' . $this->getType()); - } + $this->compareCollectionTypes($other); - $comparator = function ($a, $b): int { - // If the two values are object, we convert them to unique scalars. - // If the collection contains mixed values (unlikely) where some are objects - // and some are not, we leave them as they are. - // The comparator should still work and the result of $a < $b should - // be consistent but unpredictable since not documented. - if (is_object($a) && is_object($b)) { - $a = spl_object_id($a); - $b = spl_object_id($b); - } - - return $a === $b ? 0 : ($a < $b ? 1 : -1); - }; + $diffAtoB = array_udiff($this->data, $other->toArray(), $this->getComparator()); + $diffBtoA = array_udiff($other->toArray(), $this->data, $this->getComparator()); - $diffAtoB = array_udiff($this->data, $other->data, $comparator); - $diffBtoA = array_udiff($other->data, $this->data, $comparator); + /** @var array<array-key, T> $diff */ $diff = array_merge($diffAtoB, $diffBtoA); $collection = clone $this; @@ -314,45 +223,12 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt return $collection; } - /** - * Create a new collection with intersecting item between current and given - * collection. - * - * @param CollectionInterface<mixed, mixed> $other The collection to check for - * intersecting items. - * - * @return CollectionInterface<mixed, mixed> - * - * @throws CollectionMismatchException if the given collection is not of the - * same type. - */ public function intersect(CollectionInterface $other): CollectionInterface { - if (!$other instanceof static) { - throw new CollectionMismatchException('Collection must be of type ' . static::class); - } - - // When using generics (Collection.php, Set.php, etc), - // we also need to make sure that the internal types match each other - if ($other->getType() !== $this->getType()) { - throw new CollectionMismatchException('Collection items must be of type ' . $this->getType()); - } + $this->compareCollectionTypes($other); - $comparator = function ($a, $b): int { - // If the two values are object, we convert them to unique scalars. - // If the collection contains mixed values (unlikely) where some are objects - // and some are not, we leave them as they are. - // The comparator should still work and the result of $a < $b should - // be consistent but unpredictable since not documented. - if (is_object($a) && is_object($b)) { - $a = spl_object_id($a); - $b = spl_object_id($b); - } - - return $a === $b ? 0 : ($a < $b ? 1 : -1); - }; - - $intersect = array_uintersect($this->data, $other->data, $comparator); + /** @var array<array-key, T> $intersect */ + $intersect = array_uintersect($this->data, $other->toArray(), $this->getComparator()); $collection = clone $this; $collection->data = $intersect; @@ -360,15 +236,6 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt return $collection; } - /** - * Merge current items and items of given collections into a new one. - * - * @param CollectionInterface<mixed, mixed> ...$collections The collections to merge. - * - * @return CollectionInterface<mixed, mixed> - * - * @throws CollectionMismatchException if any of the given collections are not of the same type. - */ public function merge(CollectionInterface ...$collections): CollectionInterface { $temp = [$this->data]; @@ -391,6 +258,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt $temp[] = $collection->toArray(); } + /** @var array<array-key, T> $merge */ $merge = array_merge(...$temp); $collection = clone $this; @@ -404,6 +272,46 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt */ public function unserialize($serialized): void { - $this->data = unserialize($serialized, ['allowed_classes' => [$this->getType()]]); + /** @var array<array-key, T> $data */ + $data = unserialize($serialized, ['allowed_classes' => [$this->getType()]]); + + $this->data = $data; + } + + /** + * @param CollectionInterface<T> $other + */ + private function compareCollectionTypes(CollectionInterface $other): void + { + if (!$other instanceof static) { + throw new CollectionMismatchException('Collection must be of type ' . static::class); + } + + // When using generics (Collection.php, Set.php, etc), + // we also need to make sure that the internal types match each other + if ($other->getType() !== $this->getType()) { + throw new CollectionMismatchException('Collection items must be of type ' . $this->getType()); + } + } + + private function getComparator(): Closure + { + return /** + * @param T $a + * @param T $b + */ + function ($a, $b): int { + // If the two values are object, we convert them to unique scalars. + // If the collection contains mixed values (unlikely) where some are objects + // and some are not, we leave them as they are. + // The comparator should still work and the result of $a < $b should + // be consistent but unpredictable since not documented. + if (is_object($a) && is_object($b)) { + $a = spl_object_id($a); + $b = spl_object_id($b); + } + + return $a === $b ? 0 : ($a < $b ? 1 : -1); + }; } } diff --git a/vendor/ramsey/collection/src/AbstractSet.php b/vendor/ramsey/collection/src/AbstractSet.php index 674fda03d..3bd22965f 100644 --- a/vendor/ramsey/collection/src/AbstractSet.php +++ b/vendor/ramsey/collection/src/AbstractSet.php @@ -14,25 +14,18 @@ declare(strict_types=1); namespace Ramsey\Collection; -use Ramsey\Collection\Exception\InvalidArgumentException; - /** * This class contains the basic implementation of a collection that does not * allow duplicated values (a set), to minimize the effort required to implement * this specific type of collection. + * + * @template T + * @template-extends AbstractCollection<T> */ abstract class AbstractSet extends AbstractCollection { /** - * Adds the specified element to this set, if it is not already present. - * - * @param mixed $element The element to add to the set. - * - * @return bool `true` if this set did not already contain the specified - * element. - * - * @throws InvalidArgumentException when the element does not match the - * specified type for this set. + * @inheritDoc */ public function add($element): bool { @@ -44,14 +37,7 @@ abstract class AbstractSet extends AbstractCollection } /** - * Sets the given value to the given offset in this set, if it is not - * already present. - * - * @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 set. + * @inheritDoc */ public function offsetSet($offset, $value): void { diff --git a/vendor/ramsey/collection/src/ArrayInterface.php b/vendor/ramsey/collection/src/ArrayInterface.php index 81835cc80..19fbff336 100644 --- a/vendor/ramsey/collection/src/ArrayInterface.php +++ b/vendor/ramsey/collection/src/ArrayInterface.php @@ -21,6 +21,8 @@ use Serializable; /** * `ArrayInterface` provides traversable array functionality to data types. + * + * @template T */ interface ArrayInterface extends ArrayAccess, @@ -36,7 +38,7 @@ interface ArrayInterface extends /** * Returns a native PHP array representation of this array object. * - * @return mixed[] + * @return array<array-key, T> */ public function toArray(): array; diff --git a/vendor/ramsey/collection/src/Collection.php b/vendor/ramsey/collection/src/Collection.php index e4db68dfe..2f8deddaa 100644 --- a/vendor/ramsey/collection/src/Collection.php +++ b/vendor/ramsey/collection/src/Collection.php @@ -69,6 +69,9 @@ namespace Ramsey\Collection; * // the collection is a collection of My\Foo objects * } * ``` + * + * @template T + * @template-extends AbstractCollection<T> */ class Collection extends AbstractCollection { @@ -88,7 +91,7 @@ class Collection extends AbstractCollection * * @param string $collectionType The type (FQCN) associated with this * collection. - * @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 $collectionType, array $data = []) { @@ -96,9 +99,6 @@ class Collection extends AbstractCollection parent::__construct($data); } - /** - * Returns the type associated with this collection. - */ public function getType(): string { return $this->collectionType; diff --git a/vendor/ramsey/collection/src/CollectionInterface.php b/vendor/ramsey/collection/src/CollectionInterface.php index c865fa9f5..dfef6ca86 100644 --- a/vendor/ramsey/collection/src/CollectionInterface.php +++ b/vendor/ramsey/collection/src/CollectionInterface.php @@ -19,6 +19,9 @@ namespace Ramsey\Collection; * * Some collections allow duplicate elements and others do not. Some are ordered * and others unordered. + * + * @template T + * @template-extends ArrayInterface<T> */ interface CollectionInterface extends ArrayInterface { @@ -52,18 +55,20 @@ interface CollectionInterface extends ArrayInterface * (rather than returning `false`). This preserves the invariant that a * collection always contains the specified element after this call returns. * - * @param mixed $element The element to add to the collection. + * @param T $element The element to add to the collection. * * @return bool `true` if this collection changed as a result of the call. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function add($element): bool; /** * Returns `true` if this collection contains the specified element. * - * @param mixed $element The element to check whether the collection contains. + * @param T $element The element to check whether the collection contains. * @param bool $strict Whether to perform a strict type check on the value. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function contains($element, bool $strict = true): bool; /** @@ -75,10 +80,11 @@ interface CollectionInterface extends ArrayInterface * Removes a single instance of the specified element from this collection, * if it is present. * - * @param mixed $element The element to remove from the collection. + * @param T $element The element to remove from the collection. * * @return bool `true` if an element was removed as a result of this call. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function remove($element): bool; /** @@ -86,21 +92,21 @@ interface CollectionInterface extends ArrayInterface * * @param string $propertyOrMethod The property or method name to filter by. * - * @return mixed[] + * @return list<mixed> */ public function column(string $propertyOrMethod): array; /** * Returns the first item of the collection. * - * @return mixed + * @return T */ public function first(); /** * Returns the last item of the collection. * - * @return mixed + * @return T */ public function last(); @@ -114,7 +120,7 @@ interface CollectionInterface extends ArrayInterface * @param string $order The sort order for the resulting collection (one of * this interface's `SORT_*` constants). * - * @return CollectionInterface<mixed, mixed> + * @return CollectionInterface<T> */ public function sort(string $propertyOrMethod, string $order = self::SORT_ASC): self; @@ -128,9 +134,9 @@ interface CollectionInterface extends ArrayInterface * See the {@link http://php.net/manual/en/function.array-filter.php PHP array_filter() documentation} * for examples of how the `$callback` parameter works. * - * @param callable $callback A callable to use for filtering elements. + * @param callable(T):bool $callback A callable to use for filtering elements. * - * @return CollectionInterface<mixed, mixed> + * @return CollectionInterface<T> */ public function filter(callable $callback): self; @@ -141,25 +147,28 @@ interface CollectionInterface extends ArrayInterface * a new one. * * @param string $propertyOrMethod The property or method to evaluate. - * @param mixed $value The value to match. + * @param mixed $value The value to match. * - * @return CollectionInterface<mixed, mixed> + * @return CollectionInterface<T> */ public function where(string $propertyOrMethod, $value): self; /** * Apply a given callback method on each item of the collection. * - * This will always leave the original collection untouched and will return - * a new one. + * This will always leave the original collection untouched. The new + * collection is created by mapping the callback to each item of the + * original collection. * * See the {@link http://php.net/manual/en/function.array-map.php PHP array_map() documentation} * for examples of how the `$callback` parameter works. * - * @param callable $callback A callable to apply to each item of the - * collection. + * @param callable(T):TCallbackReturn $callback A callable to apply to each + * item of the collection. + * + * @return CollectionInterface<TCallbackReturn> * - * @return CollectionInterface<mixed, mixed> + * @template TCallbackReturn */ public function map(callable $callback): self; @@ -167,10 +176,10 @@ interface CollectionInterface extends ArrayInterface * Create a new collection with divergent items between current and given * collection. * - * @param CollectionInterface<mixed, mixed> $other The collection to check for divergent + * @param CollectionInterface<T> $other The collection to check for divergent * items. * - * @return CollectionInterface<mixed, mixed> + * @return CollectionInterface<T> */ public function diff(CollectionInterface $other): self; @@ -178,19 +187,19 @@ interface CollectionInterface extends ArrayInterface * Create a new collection with intersecting item between current and given * collection. * - * @param CollectionInterface<mixed, mixed> $other The collection to check for + * @param CollectionInterface<T> $other The collection to check for * intersecting items. * - * @return CollectionInterface<mixed, mixed> + * @return CollectionInterface<T> */ public function intersect(CollectionInterface $other): self; /** * Merge current items and items of given collections into a new one. * - * @param CollectionInterface<mixed, mixed> ...$collections The collections to merge. + * @param CollectionInterface<T> ...$collections The collections to merge. * - * @return CollectionInterface<mixed, mixed> + * @return CollectionInterface<T> */ public function merge(CollectionInterface ...$collections): self; } diff --git a/vendor/ramsey/collection/src/DoubleEndedQueue.php b/vendor/ramsey/collection/src/DoubleEndedQueue.php index 4eb4dbeab..6ebdca5ad 100644 --- a/vendor/ramsey/collection/src/DoubleEndedQueue.php +++ b/vendor/ramsey/collection/src/DoubleEndedQueue.php @@ -20,6 +20,10 @@ use Ramsey\Collection\Exception\NoSuchElementException; /** * This class provides a basic implementation of `DoubleEndedQueueInterface`, to * minimize the effort required to implement this interface. + * + * @template T + * @template-extends Queue<T> + * @template-implements DoubleEndedQueueInterface<T> */ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface { @@ -31,19 +35,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface private $tail = -1; /** - * Sets the given value to the given offset in the queue. - * - * 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. + * @inheritDoc */ public function offsetSet($offset, $value): void { @@ -60,16 +52,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Ensures that the specified element is inserted at the front of this queue. - * - * @see self::offerFirst() - * - * @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 value does not match the - * specified type for this queue. + * @inheritDoc */ public function addFirst($element): bool { @@ -88,16 +71,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Ensures that the specified element in inserted at the end of this queue. - * - * @see Queue::add() - * - * @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 value does not match the - * specified type for this queue. + * @inheritDoc */ public function addLast($element): bool { @@ -105,13 +79,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Inserts the specified element at the front this queue. - * - * @see self::addFirst() - * - * @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 offerFirst($element): bool { @@ -123,14 +91,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Inserts the specified element at the end this queue. - * - * @see self::addLast() - * @see Queue::offer() - * - * @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 offerLast($element): bool { @@ -138,17 +99,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves and removes the head of this queue. - * - * This method differs from `pollFirst()` only in that it throws an - * exception if this queue is empty. - * - * @see self::pollFirst() - * @see Queue::remove() - * - * @return mixed the head of this queue. - * - * @throws NoSuchElementException if this queue is empty. + * @inheritDoc */ public function removeFirst() { @@ -156,38 +107,21 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves and removes the tail of this queue. - * - * This method differs from `pollLast()` only in that it throws an exception - * if this queue is empty. - * - * @see self::pollLast() - * - * @return mixed the tail of this queue. - * - * @throws NoSuchElementException if this queue is empty. + * @inheritDoc */ public function removeLast() { - if ($this->count() === 0) { + $tail = $this->pollLast(); + + if ($tail === null) { throw new NoSuchElementException('Can\'t return element from Queue. Queue is empty.'); } - $tail = $this[$this->tail]; - - unset($this[$this->tail]); - $this->tail--; - return $tail; } /** - * Retrieves and removes the head of this queue, or returns `null` if this - * queue is empty. - * - * @see self::removeFirst() - * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @inheritDoc */ public function pollFirst() { @@ -195,12 +129,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves and removes the tail of this queue, or returns `null` if this - * queue is empty. - * - * @see self::removeLast() - * - * @return mixed|null the tail of this queue, or `null` if this queue is empty. + * @inheritDoc */ public function pollLast() { @@ -217,17 +146,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves, but does not remove, the head of this queue. - * - * This method differs from `peekFirst()` only in that it throws an - * exception if this queue is empty. - * - * @see self::peekFirst() - * @see Queue::element() - * - * @return mixed the head of this queue. - * - * @throws NoSuchElementException if this queue is empty. + * @inheritDoc */ public function firstElement() { @@ -235,16 +154,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves, but does not remove, the tail of this queue. - * - * This method differs from `peekLast()` only in that it throws an exception - * if this queue is empty. - * - * @see self::peekLast() - * - * @return mixed the tail of this queue. - * - * @throws NoSuchElementException if this queue is empty. + * @inheritDoc */ public function lastElement() { @@ -256,13 +166,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves, but does not remove, the head of this queue, or returns `null` - * if this queue is empty. - * - * @see self::firstElement() - * @see Queue::peek() - * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @inheritDoc */ public function peekFirst() { @@ -270,12 +174,7 @@ class DoubleEndedQueue extends Queue implements DoubleEndedQueueInterface } /** - * Retrieves, but does not remove, the tail of this queue, or returns `null` - * if this queue is empty. - * - * @see self::lastElement() - * - * @return mixed|null the tail of this queue, or `null` if this queue is empty + * @inheritDoc */ public function peekLast() { diff --git a/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php b/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php index 6b23cf553..67aae5e2e 100644 --- a/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php +++ b/vendor/ramsey/collection/src/DoubleEndedQueueInterface.php @@ -158,6 +158,9 @@ use Ramsey\Collection\Exception\NoSuchElementException; * ability to insert nulls. This is so because `null` is used as a special * return value by various methods to indicated that the double-ended queue is * empty. + * + * @template T + * @template-extends QueueInterface<T> */ interface DoubleEndedQueueInterface extends QueueInterface { @@ -168,7 +171,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * When using a capacity-restricted double-ended queue, it is generally * preferable to use the `offerFirst()` method. * - * @param mixed $element The element to add to the front of this queue. + * @param T $element The element to add to the front of this queue. * * @return bool `true` if this queue changed as a result of the call. * @@ -177,6 +180,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * Implementations should use a more-specific exception that extends * `\RuntimeException`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function addFirst($element): bool; /** @@ -188,7 +192,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * * This method is equivalent to `add()`. * - * @param mixed $element The element to add to the end of this queue. + * @param T $element The element to add to the end of this queue. * * @return bool `true` if this queue changed as a result of the call. * @@ -197,6 +201,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * Implementations should use a more-specific exception that extends * `\RuntimeException`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function addLast($element): bool; /** @@ -207,10 +212,11 @@ interface DoubleEndedQueueInterface extends QueueInterface * preferable to `addFirst()`, which can fail to insert an element only by * throwing an exception. * - * @param mixed $element The element to add to the front of this queue. + * @param T $element The element to add to the front of this queue. * * @return bool `true` if the element was added to this queue, else `false`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function offerFirst($element): bool; /** @@ -221,10 +227,11 @@ interface DoubleEndedQueueInterface extends QueueInterface * preferable to `addLast()` which can fail to insert an element only by * throwing an exception. * - * @param mixed $element The element to add to the end of this queue. + * @param T $element The element to add to the end of this queue. * * @return bool `true` if the element was added to this queue, else `false`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function offerLast($element): bool; /** @@ -233,7 +240,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * This method differs from `pollFirst()` only in that it throws an * exception if this queue is empty. * - * @return mixed the first element in this queue. + * @return T the first element in this queue. * * @throws NoSuchElementException if this queue is empty. */ @@ -245,7 +252,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * This method differs from `pollLast()` only in that it throws an exception * if this queue is empty. * - * @return mixed the last element in this queue. + * @return T the last element in this queue. * * @throws NoSuchElementException if this queue is empty. */ @@ -255,7 +262,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * Retrieves and removes the head of this queue, or returns `null` if this * queue is empty. * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @return T|null the head of this queue, or `null` if this queue is empty. */ public function pollFirst(); @@ -263,7 +270,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * Retrieves and removes the tail of this queue, or returns `null` if this * queue is empty. * - * @return mixed|null the tail of this queue, or `null` if this queue is empty. + * @return T|null the tail of this queue, or `null` if this queue is empty. */ public function pollLast(); @@ -273,7 +280,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * This method differs from `peekFirst()` only in that it throws an * exception if this queue is empty. * - * @return mixed the head of this queue. + * @return T the head of this queue. * * @throws NoSuchElementException if this queue is empty. */ @@ -285,7 +292,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * This method differs from `peekLast()` only in that it throws an exception * if this queue is empty. * - * @return mixed the tail of this queue. + * @return T the tail of this queue. * * @throws NoSuchElementException if this queue is empty. */ @@ -295,7 +302,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * Retrieves, but does not remove, the head of this queue, or returns `null` * if this queue is empty. * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @return T|null the head of this queue, or `null` if this queue is empty. */ public function peekFirst(); @@ -303,7 +310,7 @@ interface DoubleEndedQueueInterface extends QueueInterface * Retrieves, but does not remove, the tail of this queue, or returns `null` * if this queue is empty. * - * @return mixed|null the tail of this queue, or `null` if this queue is empty. + * @return T|null the tail of this queue, or `null` if this queue is empty. */ public function peekLast(); } diff --git a/vendor/ramsey/collection/src/GenericArray.php b/vendor/ramsey/collection/src/GenericArray.php index 2f9ab7677..9b95df387 100644 --- a/vendor/ramsey/collection/src/GenericArray.php +++ b/vendor/ramsey/collection/src/GenericArray.php @@ -16,6 +16,8 @@ namespace Ramsey\Collection; /** * `GenericArray` represents a standard array object. + * + * @template-extends AbstractArray<mixed> */ class GenericArray extends AbstractArray { diff --git a/vendor/ramsey/collection/src/Map/AbstractMap.php b/vendor/ramsey/collection/src/Map/AbstractMap.php index 6b2e97a08..70f71160c 100644 --- a/vendor/ramsey/collection/src/Map/AbstractMap.php +++ b/vendor/ramsey/collection/src/Map/AbstractMap.php @@ -24,23 +24,22 @@ use function in_array; /** * This class provides a basic implementation of `MapInterface`, to minimize the * effort required to implement this interface. + * + * @template T + * @template-extends AbstractArray<T> + * @template-implements MapInterface<T> */ abstract class AbstractMap extends AbstractArray implements MapInterface { /** - * Sets the given value to the given offset in the map. - * - * @param mixed $offset The offset to set. - * @param mixed $value The value to set at the given offset. - * - * @throws InvalidArgumentException if the offset provided is `null`. + * @inheritDoc */ public function offsetSet($offset, $value): void { if ($offset === null) { throw new InvalidArgumentException( 'Map elements are key/value pairs; a key must be provided for ' - . 'value ' . $value + . 'value ' . var_export($value, true) ); } @@ -48,9 +47,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Returns `true` if this map contains a mapping for the specified key. - * - * @param mixed $key The key to check in the map. + * @inheritDoc */ public function containsKey($key): bool { @@ -58,11 +55,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Returns `true` if this map maps one or more keys to the specified value. - * - * This performs a strict type check on the value. - * - * @param mixed $value The value to check in the map. + * @inheritDoc */ public function containsValue($value): bool { @@ -70,9 +63,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Return an array of the keys contained in this map. - * - * @return mixed[] + * @inheritDoc */ public function keys(): array { @@ -80,14 +71,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Returns the value to which the specified key is mapped, `null` if this - * map contains no mapping for the key, or (optionally) `$defaultValue` if - * this map contains no mapping for the key. - * - * @param mixed $key The key to return from the map. - * @param mixed $defaultValue The default value to use if `$key` is not found. - * - * @return mixed|null the value or `null` if the key could not be found. + * @inheritDoc */ public function get($key, $defaultValue = null) { @@ -99,16 +83,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Associates the specified value with the specified key in this map. - * - * If the map previously contained a mapping for the key, the old value is - * replaced by the specified value. - * - * @param mixed $key The key to put or replace in the map. - * @param mixed $value The value to store at `$key`. - * - * @return mixed|null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ public function put($key, $value) { @@ -119,17 +94,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Associates the specified value with the specified key in this map only if - * it is not already set. - * - * If there is already a value associated with `$key`, this returns that - * value without replacing it. - * - * @param mixed $key The key to put in the map. - * @param mixed $value The value to store at `$key`. - * - * @return mixed|null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ public function putIfAbsent($key, $value) { @@ -143,12 +108,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Removes the mapping for a key from this map if it is present. - * - * @param mixed $key The key to remove from the map. - * - * @return mixed|null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ public function remove($key) { @@ -159,15 +119,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Removes the entry for the specified key only if it is currently mapped to - * the specified value. - * - * This performs a strict type check on the value. - * - * @param mixed $key The key to remove from the map. - * @param mixed $value The value to match. - * - * @return bool true if the value was removed. + * @inheritDoc */ public function removeIf($key, $value): bool { @@ -181,14 +133,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Replaces the entry for the specified key only if it is currently mapped - * to some value. - * - * @param mixed $key The key to replace. - * @param mixed $value The value to set at `$key`. - * - * @return mixed|null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ public function replace($key, $value) { @@ -202,16 +147,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * Replaces the entry for the specified key only if currently mapped to the - * specified value. - * - * This performs a strict type check on the value. - * - * @param mixed $key The key to remove from the map. - * @param mixed $oldValue The value to match. - * @param mixed $newValue The value to use as a replacement. - * - * @return bool true if the value was replaced. + * @inheritDoc */ public function replaceIf($key, $oldValue, $newValue): bool { diff --git a/vendor/ramsey/collection/src/Map/AbstractTypedMap.php b/vendor/ramsey/collection/src/Map/AbstractTypedMap.php index 80cec2e22..ff9f69177 100644 --- a/vendor/ramsey/collection/src/Map/AbstractTypedMap.php +++ b/vendor/ramsey/collection/src/Map/AbstractTypedMap.php @@ -21,6 +21,12 @@ use Ramsey\Collection\Tool\ValueToStringTrait; /** * This class provides a basic implementation of `TypedMapInterface`, to * minimize the effort required to implement this interface. + * + * @phpstan-ignore-next-line + * @template K as array-key + * @template T + * @template-extends AbstractMap<T> + * @template-implements TypedMapInterface<T> */ abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface { @@ -28,16 +34,22 @@ abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface use ValueToStringTrait; /** - * Sets the given value to the given offset in the map. + * @param K|null $offset + * @param T $value * - * @param mixed $offset The offset to set. - * @param mixed $value The value to set at the given offset. + * @inheritDoc * - * @throws InvalidArgumentException if the offset or value do not match the - * expected types. + * @psalm-suppress MoreSpecificImplementedParamType */ public function offsetSet($offset, $value): void { + if ($offset === null) { + throw new InvalidArgumentException( + 'Map elements are key/value pairs; a key must be provided for ' + . 'value ' . var_export($value, true) + ); + } + if ($this->checkType($this->getKeyType(), $offset) === false) { throw new InvalidArgumentException( 'Key must be of type ' . $this->getKeyType() . '; key is ' diff --git a/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php index f97e21728..3274dc9de 100644 --- a/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php +++ b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php @@ -16,6 +16,9 @@ namespace Ramsey\Collection\Map; /** * `AssociativeArrayMap` represents a standard associative array object. + * + * @template T + * @template-extends AbstractMap<T> */ class AssociativeArrayMap extends AbstractMap { diff --git a/vendor/ramsey/collection/src/Map/MapInterface.php b/vendor/ramsey/collection/src/Map/MapInterface.php index 500bdb2d0..04e52a238 100644 --- a/vendor/ramsey/collection/src/Map/MapInterface.php +++ b/vendor/ramsey/collection/src/Map/MapInterface.php @@ -20,13 +20,16 @@ use Ramsey\Collection\ArrayInterface; * An object that maps keys to values. * * A map cannot contain duplicate keys; each key can map to at most one value. + * + * @template T + * @template-extends ArrayInterface<T> */ interface MapInterface extends ArrayInterface { /** * Returns `true` if this map contains a mapping for the specified key. * - * @param mixed $key The key to check in the map. + * @param array-key $key The key to check in the map. */ public function containsKey($key): bool; @@ -35,14 +38,15 @@ interface MapInterface extends ArrayInterface * * This performs a strict type check on the value. * - * @param mixed $value The value to check in the map. + * @param T $value The value to check in the map. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function containsValue($value): bool; /** * Return an array of the keys contained in this map. * - * @return mixed[] + * @return list<array-key> */ public function keys(): array; @@ -51,11 +55,12 @@ interface MapInterface extends ArrayInterface * map contains no mapping for the key, or (optionally) `$defaultValue` if * this map contains no mapping for the key. * - * @param mixed $key The key to return from the map. - * @param mixed $defaultValue The default value to use if `$key` is not found. + * @param array-key $key The key to return from the map. + * @param T|null $defaultValue The default value to use if `$key` is not found. * - * @return mixed|null the value or `null` if the key could not be found. + * @return T|null the value or `null` if the key could not be found. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function get($key, $defaultValue = null); /** @@ -64,12 +69,13 @@ interface MapInterface extends ArrayInterface * If the map previously contained a mapping for the key, the old value is * replaced by the specified value. * - * @param mixed $key The key to put or replace in the map. - * @param mixed $value The value to store at `$key`. + * @param array-key $key The key to put or replace in the map. + * @param T $value The value to store at `$key`. * - * @return mixed|null the previous value associated with key, or `null` if + * @return T|null the previous value associated with key, or `null` if * there was no mapping for `$key`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function put($key, $value); /** @@ -79,22 +85,24 @@ interface MapInterface extends ArrayInterface * If there is already a value associated with `$key`, this returns that * value without replacing it. * - * @param mixed $key The key to put in the map. - * @param mixed $value The value to store at `$key`. + * @param array-key $key The key to put in the map. + * @param T $value The value to store at `$key`. * - * @return mixed|null the previous value associated with key, or `null` if + * @return T|null the previous value associated with key, or `null` if * there was no mapping for `$key`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function putIfAbsent($key, $value); /** * Removes the mapping for a key from this map if it is present. * - * @param mixed $key The key to remove from the map. + * @param array-key $key The key to remove from the map. * - * @return mixed|null the previous value associated with key, or `null` if + * @return T|null the previous value associated with key, or `null` if * there was no mapping for `$key`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function remove($key); /** @@ -103,23 +111,25 @@ interface MapInterface extends ArrayInterface * * This performs a strict type check on the value. * - * @param mixed $key The key to remove from the map. - * @param mixed $value The value to match. + * @param array-key $key The key to remove from the map. + * @param T $value The value to match. * * @return bool true if the value was removed. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function removeIf($key, $value): bool; /** * Replaces the entry for the specified key only if it is currently mapped * to some value. * - * @param mixed $key The key to replace. - * @param mixed $value The value to set at `$key`. + * @param array-key $key The key to replace. + * @param T $value The value to set at `$key`. * - * @return mixed|null the previous value associated with key, or `null` if + * @return T|null the previous value associated with key, or `null` if * there was no mapping for `$key`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function replace($key, $value); /** @@ -128,11 +138,12 @@ interface MapInterface extends ArrayInterface * * This performs a strict type check on the value. * - * @param mixed $key The key to remove from the map. - * @param mixed $oldValue The value to match. - * @param mixed $newValue The value to use as a replacement. + * @param array-key $key The key to remove from the map. + * @param T $oldValue The value to match. + * @param T $newValue The value to use as a replacement. * * @return bool true if the value was replaced. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function replaceIf($key, $oldValue, $newValue): bool; } diff --git a/vendor/ramsey/collection/src/Map/NamedParameterMap.php b/vendor/ramsey/collection/src/Map/NamedParameterMap.php index 7adfa0afd..ecc52f73a 100644 --- a/vendor/ramsey/collection/src/Map/NamedParameterMap.php +++ b/vendor/ramsey/collection/src/Map/NamedParameterMap.php @@ -25,6 +25,8 @@ use function is_int; /** * `NamedParameterMap` represents a mapping of values to a set of named keys * that may optionally be typed + * + * @template-extends AbstractMap<mixed> */ class NamedParameterMap extends AbstractMap { @@ -34,15 +36,15 @@ class NamedParameterMap extends AbstractMap /** * Named parameters defined for this map. * - * @var array<mixed, string> + * @var array<string, string> */ protected $namedParameters; /** * Constructs a new `NamedParameterMap`. * - * @param array<mixed, string> $namedParameters The named parameters defined for this map. - * @param mixed[] $data An initial set of data to set on this map. + * @param array<array-key, string> $namedParameters The named parameters defined for this map. + * @param array<array-key, mixed> $data An initial set of data to set on this map. */ public function __construct(array $namedParameters, array $data = []) { @@ -53,7 +55,7 @@ class NamedParameterMap extends AbstractMap /** * Returns named parameters set for this `NamedParameterMap`. * - * @return array<mixed, string> + * @return array<string, string> */ public function getNamedParameters(): array { @@ -61,17 +63,17 @@ class NamedParameterMap extends AbstractMap } /** - * Sets the given value to the given offset in the map. - * - * @param mixed $offset The offset to set. - * @param mixed $value The value to set at the given offset. - * - * @throws InvalidArgumentException if the offset provided is not a - * defined named parameter, or if the value is not of the type defined - * for the given named parameter. + * @inheritDoc */ public function offsetSet($offset, $value): void { + if ($offset === null) { + throw new InvalidArgumentException( + 'Map elements are key/value pairs; a key must be provided for ' + . 'value ' . var_export($value, true) + ); + } + if (!array_key_exists($offset, $this->namedParameters)) { throw new InvalidArgumentException( 'Attempting to set value for unconfigured parameter \'' @@ -94,9 +96,9 @@ class NamedParameterMap extends AbstractMap * Given an array of named parameters, constructs a proper mapping of * named parameters to types. * - * @param array<mixed, string> $namedParameters The named parameters to filter. + * @param array<array-key, string> $namedParameters The named parameters to filter. * - * @return array<mixed, string> + * @return array<string, string> */ protected function filterNamedParameters(array $namedParameters): array { @@ -105,11 +107,11 @@ class NamedParameterMap extends AbstractMap foreach ($namedParameters as $key => $value) { if (is_int($key)) { - $names[] = (string) $value; + $names[] = $value; $types[] = 'mixed'; } else { $names[] = $key; - $types[] = (string) $value; + $types[] = $value; } } diff --git a/vendor/ramsey/collection/src/Map/TypedMap.php b/vendor/ramsey/collection/src/Map/TypedMap.php index 84d075f80..752475fee 100644 --- a/vendor/ramsey/collection/src/Map/TypedMap.php +++ b/vendor/ramsey/collection/src/Map/TypedMap.php @@ -79,6 +79,11 @@ use Ramsey\Collection\Tool\TypeTrait; * } * } * ``` + * + * @phpstan-ignore-next-line + * @template K as array-key + * @template T + * @template-extends AbstractTypedMap<K, T> */ class TypedMap extends AbstractTypedMap { @@ -97,7 +102,7 @@ class TypedMap extends AbstractTypedMap /** * The data type of values stored in this collection. * - * A map values's type is immutable once it is set. For this reason, this + * A map value's type is immutable once it is set. For this reason, this * property is set private. * * @var string data type of the map value. @@ -110,7 +115,7 @@ class TypedMap extends AbstractTypedMap * * @param string $keyType The data type of the map's keys. * @param string $valueType The data type of the map's values. - * @param mixed[] $data The initial data to set for this map. + * @param array<K, T> $data The initial data to set for this map. */ public function __construct(string $keyType, string $valueType, array $data = []) { @@ -119,17 +124,11 @@ class TypedMap extends AbstractTypedMap parent::__construct($data); } - /** - * Return the type used on the key. - */ public function getKeyType(): string { return $this->keyType; } - /** - * Return the type forced on the values. - */ public function getValueType(): string { return $this->valueType; diff --git a/vendor/ramsey/collection/src/Map/TypedMapInterface.php b/vendor/ramsey/collection/src/Map/TypedMapInterface.php index 54c783695..51b6a81a2 100644 --- a/vendor/ramsey/collection/src/Map/TypedMapInterface.php +++ b/vendor/ramsey/collection/src/Map/TypedMapInterface.php @@ -17,6 +17,9 @@ namespace Ramsey\Collection\Map; /** * A `TypedMapInterface` represents a map of elements where key and value are * typed. + * + * @template T + * @template-extends MapInterface<T> */ interface TypedMapInterface extends MapInterface { 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; diff --git a/vendor/ramsey/collection/src/QueueInterface.php b/vendor/ramsey/collection/src/QueueInterface.php index 6c7f2ac2c..7ebbb5d06 100644 --- a/vendor/ramsey/collection/src/QueueInterface.php +++ b/vendor/ramsey/collection/src/QueueInterface.php @@ -92,6 +92,9 @@ use Ramsey\Collection\Exception\NoSuchElementException; * Even in the implementations that permit it, `null` should not be inserted * into a queue, as `null` is also used as a special return value by the * `poll()` method to indicate that the queue contains no elements. + * + * @template T + * @template-extends ArrayInterface<T> */ interface QueueInterface extends ArrayInterface { @@ -116,7 +119,7 @@ interface QueueInterface extends ArrayInterface * * @see self::offer() * - * @param mixed $element The element to add to this queue. + * @param T $element The element to add to this queue. * * @return bool `true` if this queue changed as a result of the call. * @@ -125,6 +128,7 @@ interface QueueInterface extends ArrayInterface * Implementations should use a more-specific exception that extends * `\RuntimeException`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function add($element): bool; /** @@ -135,7 +139,7 @@ interface QueueInterface extends ArrayInterface * * @see self::peek() * - * @return mixed the head of this queue. + * @return T the head of this queue. * * @throws NoSuchElementException if this queue is empty. */ @@ -151,10 +155,11 @@ interface QueueInterface extends ArrayInterface * * @see self::add() * - * @param mixed $element The element to add to this queue. + * @param T $element The element to add to this queue. * * @return bool `true` if the element was added to this queue, else `false`. */ + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint public function offer($element): bool; /** @@ -163,7 +168,7 @@ interface QueueInterface extends ArrayInterface * * @see self::element() * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @return T|null the head of this queue, or `null` if this queue is empty. */ public function peek(); @@ -173,7 +178,7 @@ interface QueueInterface extends ArrayInterface * * @see self::remove() * - * @return mixed|null the head of this queue, or `null` if this queue is empty. + * @return T|null the head of this queue, or `null` if this queue is empty. */ public function poll(); @@ -185,7 +190,7 @@ interface QueueInterface extends ArrayInterface * * @see self::poll() * - * @return mixed the head of this queue. + * @return T the head of this queue. * * @throws NoSuchElementException if this queue is empty. */ diff --git a/vendor/ramsey/collection/src/Set.php b/vendor/ramsey/collection/src/Set.php index 42fb66c36..ac1c5cbf0 100644 --- a/vendor/ramsey/collection/src/Set.php +++ b/vendor/ramsey/collection/src/Set.php @@ -34,6 +34,9 @@ namespace Ramsey\Collection; * $bar = new \My\Foo(); * $set->add($bar); // returns TRUE, $bar !== $foo * ``` + * + * @template T + * @template-extends AbstractSet<T> */ class Set extends AbstractSet { @@ -51,7 +54,7 @@ class Set extends AbstractSet * specified data. * * @param string $setType The type (FQCN) associated with this set. - * @param mixed[] $data The initial items to store in the set. + * @param array<array-key, T> $data The initial items to store in the set. */ public function __construct(string $setType, array $data = []) { @@ -59,9 +62,6 @@ class Set extends AbstractSet parent::__construct($data); } - /** - * Returns the type associated with this set. - */ public function getType(): string { return $this->setType; diff --git a/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php b/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php index 7bc4878db..f9be1be28 100644 --- a/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php +++ b/vendor/ramsey/collection/src/Tool/ValueExtractorTrait.php @@ -29,7 +29,7 @@ trait ValueExtractorTrait /** * Extracts the value of the given property or method from the object. * - * @param object $object The object to extract the value from. + * @param mixed $object The object to extract the value from. * @param string $propertyOrMethod The property or method for which the * value should be extracted. * @@ -37,8 +37,12 @@ trait ValueExtractorTrait * * @throws ValueExtractionException if the method or property is not defined. */ - protected function extractValue(object $object, string $propertyOrMethod) + protected function extractValue($object, string $propertyOrMethod) { + if (!is_object($object)) { + throw new ValueExtractionException('Unable to extract a value from a non-object'); + } + if (property_exists($object, $propertyOrMethod)) { return $object->$propertyOrMethod; } diff --git a/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php b/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php index 34a9a0a68..721ade002 100644 --- a/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php +++ b/vendor/ramsey/collection/src/Tool/ValueToStringTrait.php @@ -71,7 +71,12 @@ trait ValueToStringTrait return '(' . get_resource_type($value) . ' resource #' . (int) $value . ')'; } - // after this line $value is an object since is not null, scalar, array or resource + // If we don't know what it is, use var_export(). + if (!is_object($value)) { + return '(' . var_export($value, true) . ')'; + } + + // From here, $value should be an object. // __toString() is implemented if (is_callable([$value, '__toString'])) { |