diff options
Diffstat (limited to 'vendor/ramsey/collection/src/Map')
7 files changed, 133 insertions, 123 deletions
diff --git a/vendor/ramsey/collection/src/Map/AbstractMap.php b/vendor/ramsey/collection/src/Map/AbstractMap.php index 7a851a80f..ae9f2fe61 100644 --- a/vendor/ramsey/collection/src/Map/AbstractMap.php +++ b/vendor/ramsey/collection/src/Map/AbstractMap.php @@ -16,65 +16,48 @@ namespace Ramsey\Collection\Map; use Ramsey\Collection\AbstractArray; use Ramsey\Collection\Exception\InvalidArgumentException; -use Traversable; use function array_key_exists; use function array_keys; use function in_array; -use function var_export; /** * This class provides a basic implementation of `MapInterface`, to minimize the * effort required to implement this interface. * - * @template K of array-key * @template T * @extends AbstractArray<T> - * @implements MapInterface<K, T> + * @implements MapInterface<T> */ abstract class AbstractMap extends AbstractArray implements MapInterface { /** - * @param array<K, T> $data The initial items to add to this map. - */ - public function __construct(array $data = []) - { - parent::__construct($data); - } - - /** - * @return Traversable<K, T> - */ - public function getIterator(): Traversable - { - return parent::getIterator(); - } - - /** - * @param K $offset The offset to set - * @param T $value The value to set at the given offset. - * * @inheritDoc - * @psalm-suppress MoreSpecificImplementedParamType,DocblockTypeContradiction */ - public function offsetSet(mixed $offset, mixed $value): void + 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), + . 'value ' . var_export($value, true) ); } $this->data[$offset] = $value; } - public function containsKey(int | string $key): bool + /** + * @inheritDoc + */ + public function containsKey($key): bool { return array_key_exists($key, $this->data); } - public function containsValue(mixed $value): bool + /** + * @inheritDoc + */ + public function containsValue($value): bool { return in_array($value, $this->data, true); } @@ -88,24 +71,21 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * @param K $key The key to return from the map. - * @param T | null $defaultValue The default value to use if `$key` is not found. - * - * @return T | null the value or `null` if the key could not be found. + * @inheritDoc */ - public function get(int | string $key, mixed $defaultValue = null): mixed + public function get($key, $defaultValue = null) { - return $this[$key] ?? $defaultValue; + if (!$this->containsKey($key)) { + return $defaultValue; + } + + return $this[$key]; } /** - * @param K $key The key to put or replace in the map. - * @param T $value The value to store at `$key`. - * - * @return T | null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ - public function put(int | string $key, mixed $value): mixed + public function put($key, $value) { $previousValue = $this->get($key); $this[$key] = $value; @@ -114,13 +94,9 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * @param K $key The key to put in the map. - * @param T $value The value to store at `$key`. - * - * @return T | null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ - public function putIfAbsent(int | string $key, mixed $value): mixed + public function putIfAbsent($key, $value) { $currentValue = $this->get($key); @@ -132,12 +108,9 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * @param K $key The key to remove from the map. - * - * @return T | null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ - public function remove(int | string $key): mixed + public function remove($key) { $previousValue = $this->get($key); unset($this[$key]); @@ -145,7 +118,10 @@ abstract class AbstractMap extends AbstractArray implements MapInterface return $previousValue; } - public function removeIf(int | string $key, mixed $value): bool + /** + * @inheritDoc + */ + public function removeIf($key, $value): bool { if ($this->get($key) === $value) { unset($this[$key]); @@ -157,13 +133,9 @@ abstract class AbstractMap extends AbstractArray implements MapInterface } /** - * @param K $key The key to replace. - * @param T $value The value to set at `$key`. - * - * @return T | null the previous value associated with key, or `null` if - * there was no mapping for `$key`. + * @inheritDoc */ - public function replace(int | string $key, mixed $value): mixed + public function replace($key, $value) { $currentValue = $this->get($key); @@ -174,7 +146,10 @@ abstract class AbstractMap extends AbstractArray implements MapInterface return $currentValue; } - public function replaceIf(int | string $key, mixed $oldValue, mixed $newValue): bool + /** + * @inheritDoc + */ + public function replaceIf($key, $oldValue, $newValue): bool { if ($this->get($key) === $oldValue) { $this[$key] = $newValue; @@ -184,20 +159,4 @@ abstract class AbstractMap extends AbstractArray implements MapInterface return false; } - - /** - * @return array<K, T> - */ - public function __serialize(): array - { - return parent::__serialize(); - } - - /** - * @return array<K, T> - */ - public function toArray(): array - { - return parent::toArray(); - } } diff --git a/vendor/ramsey/collection/src/Map/AbstractTypedMap.php b/vendor/ramsey/collection/src/Map/AbstractTypedMap.php index 92fdcd54c..551d2e6c6 100644 --- a/vendor/ramsey/collection/src/Map/AbstractTypedMap.php +++ b/vendor/ramsey/collection/src/Map/AbstractTypedMap.php @@ -22,10 +22,10 @@ use Ramsey\Collection\Tool\ValueToStringTrait; * This class provides a basic implementation of `TypedMapInterface`, to * minimize the effort required to implement this interface. * - * @template K of array-key + * @template K * @template T - * @extends AbstractMap<K, T> - * @implements TypedMapInterface<K, T> + * @extends AbstractMap<T> + * @implements TypedMapInterface<T> */ abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface { @@ -33,28 +33,37 @@ abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface use ValueToStringTrait; /** - * @param K $offset + * @param K|null $offset * @param T $value * * @inheritDoc + * * @psalm-suppress MoreSpecificImplementedParamType */ - public function offsetSet(mixed $offset, mixed $value): void + 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 ' - . $this->toolValueToString($offset), + . $this->toolValueToString($offset) ); } if ($this->checkType($this->getValueType(), $value) === false) { throw new InvalidArgumentException( 'Value must be of type ' . $this->getValueType() . '; value is ' - . $this->toolValueToString($value), + . $this->toolValueToString($value) ); } + /** @psalm-suppress MixedArgumentTypeCoercion */ parent::offsetSet($offset, $value); } } diff --git a/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php index 34e4e853b..79a314d96 100644 --- a/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php +++ b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php @@ -17,7 +17,8 @@ namespace Ramsey\Collection\Map; /** * `AssociativeArrayMap` represents a standard associative array object. * - * @extends AbstractMap<string, mixed> + * @template T + * @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 22ba1bdd1..6ed0b2967 100644 --- a/vendor/ramsey/collection/src/Map/MapInterface.php +++ b/vendor/ramsey/collection/src/Map/MapInterface.php @@ -21,7 +21,6 @@ use Ramsey\Collection\ArrayInterface; * * A map cannot contain duplicate keys; each key can map to at most one value. * - * @template K of array-key * @template T * @extends ArrayInterface<T> */ @@ -30,9 +29,9 @@ interface MapInterface extends ArrayInterface /** * Returns `true` if this map contains a mapping for the specified key. * - * @param K $key The key to check in the map. + * @param array-key $key The key to check in the map. */ - public function containsKey(int | string $key): bool; + public function containsKey($key): bool; /** * Returns `true` if this map maps one or more keys to the specified value. @@ -41,12 +40,13 @@ interface MapInterface extends ArrayInterface * * @param T $value The value to check in the map. */ - public function containsValue(mixed $value): bool; + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function containsValue($value): bool; /** * Return an array of the keys contained in this map. * - * @return list<K> + * @return list<array-key> */ public function keys(): array; @@ -55,12 +55,13 @@ interface MapInterface extends ArrayInterface * map contains no mapping for the key, or (optionally) `$defaultValue` if * this map contains no mapping for the key. * - * @param K $key The key to return from the map. - * @param T | null $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 T | 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. */ - public function get(int | string $key, mixed $defaultValue = null): mixed; + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function get($key, $defaultValue = null); /** * Associates the specified value with the specified key in this map. @@ -68,13 +69,14 @@ interface MapInterface extends ArrayInterface * If the map previously contained a mapping for the key, the old value is * replaced by the specified value. * - * @param K $key The key to put or replace in the map. + * @param array-key $key The key to put or replace in the map. * @param T $value The value to store at `$key`. * - * @return T | 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`. */ - public function put(int | string $key, mixed $value): mixed; + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function put($key, $value); /** * Associates the specified value with the specified key in this map only if @@ -83,23 +85,25 @@ interface MapInterface extends ArrayInterface * If there is already a value associated with `$key`, this returns that * value without replacing it. * - * @param K $key The key to put in the map. + * @param array-key $key The key to put in the map. * @param T $value The value to store at `$key`. * - * @return T | 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`. */ - public function putIfAbsent(int | string $key, mixed $value): mixed; + // 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 K $key The key to remove from the map. + * @param array-key $key The key to remove from the map. * - * @return T | 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`. */ - public function remove(int | string $key): mixed; + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function remove($key); /** * Removes the entry for the specified key only if it is currently mapped to @@ -107,24 +111,26 @@ interface MapInterface extends ArrayInterface * * This performs a strict type check on the value. * - * @param K $key The key to remove from the map. + * @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. */ - public function removeIf(int | string $key, mixed $value): bool; + // 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 K $key The key to replace. + * @param array-key $key The key to replace. * @param T $value The value to set at `$key`. * - * @return T | 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`. */ - public function replace(int | string $key, mixed $value): mixed; + // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + public function replace($key, $value); /** * Replaces the entry for the specified key only if currently mapped to the @@ -132,11 +138,12 @@ interface MapInterface extends ArrayInterface * * This performs a strict type check on the value. * - * @param K $key The key to remove from the map. + * @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. */ - public function replaceIf(int | string $key, mixed $oldValue, mixed $newValue): bool; + // 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 f948e476c..9926ddd8c 100644 --- a/vendor/ramsey/collection/src/Map/NamedParameterMap.php +++ b/vendor/ramsey/collection/src/Map/NamedParameterMap.php @@ -26,7 +26,7 @@ use function is_int; * `NamedParameterMap` represents a mapping of values to a set of named keys * that may optionally be typed * - * @extends AbstractMap<string, mixed> + * @extends AbstractMap<mixed> */ class NamedParameterMap extends AbstractMap { @@ -38,13 +38,13 @@ class NamedParameterMap extends AbstractMap * * @var array<string, string> */ - private readonly array $namedParameters; + protected $namedParameters; /** * Constructs a new `NamedParameterMap`. * * @param array<array-key, string> $namedParameters The named parameters defined for this map. - * @param array<string, mixed> $data An initial set of data to set on 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 = []) { @@ -62,12 +62,22 @@ class NamedParameterMap extends AbstractMap return $this->namedParameters; } - public function offsetSet(mixed $offset, mixed $value): void + /** + * @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 \'' - . $this->toolValueToString($offset) . '\'', + . $offset . '\'' ); } @@ -75,7 +85,7 @@ class NamedParameterMap extends AbstractMap throw new InvalidArgumentException( 'Value for \'' . $offset . '\' must be of type ' . $this->namedParameters[$offset] . '; value is ' - . $this->toolValueToString($value), + . $this->toolValueToString($value) ); } diff --git a/vendor/ramsey/collection/src/Map/TypedMap.php b/vendor/ramsey/collection/src/Map/TypedMap.php index f914d9c70..2e796377a 100644 --- a/vendor/ramsey/collection/src/Map/TypedMap.php +++ b/vendor/ramsey/collection/src/Map/TypedMap.php @@ -14,11 +14,13 @@ declare(strict_types=1); namespace Ramsey\Collection\Map; +use Ramsey\Collection\Tool\TypeTrait; + /** * A `TypedMap` represents a map of elements where key and value are typed. * * Each element is identified by a key with defined type and a value of defined - * type. The keys of the map must be unique. The values on the map can be + * type. The keys of the map must be unique. The values on the map can be= * repeated but each with its own different key. * * The most common case is to use a string type key, but it's not limited to @@ -78,12 +80,34 @@ namespace Ramsey\Collection\Map; * } * ``` * - * @template K of array-key + * @template K * @template T * @extends AbstractTypedMap<K, T> */ class TypedMap extends AbstractTypedMap { + use TypeTrait; + + /** + * The data type of keys stored in this collection. + * + * A map key's type is immutable once it is set. For this reason, this + * property is set private. + * + * @var string data type of the map key. + */ + private $keyType; + + /** + * The data type of values stored in this collection. + * + * 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. + */ + private $valueType; + /** * Constructs a map object of the specified key and value types, * optionally with the specified data. @@ -92,11 +116,12 @@ class TypedMap extends AbstractTypedMap * @param string $valueType The data type of the map's values. * @param array<K, T> $data The initial data to set for this map. */ - public function __construct( - private readonly string $keyType, - private readonly string $valueType, - array $data = [], - ) { + public function __construct(string $keyType, string $valueType, array $data = []) + { + $this->keyType = $keyType; + $this->valueType = $valueType; + + /** @psalm-suppress MixedArgumentTypeCoercion */ parent::__construct($data); } diff --git a/vendor/ramsey/collection/src/Map/TypedMapInterface.php b/vendor/ramsey/collection/src/Map/TypedMapInterface.php index 5a44f0647..0308109cc 100644 --- a/vendor/ramsey/collection/src/Map/TypedMapInterface.php +++ b/vendor/ramsey/collection/src/Map/TypedMapInterface.php @@ -18,9 +18,8 @@ namespace Ramsey\Collection\Map; * A `TypedMapInterface` represents a map of elements where key and value are * typed. * - * @template K of array-key * @template T - * @extends MapInterface<K, T> + * @extends MapInterface<T> */ interface TypedMapInterface extends MapInterface { |