aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/collection/src/Map
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ramsey/collection/src/Map')
-rw-r--r--vendor/ramsey/collection/src/Map/AbstractMap.php109
-rw-r--r--vendor/ramsey/collection/src/Map/AbstractTypedMap.php23
-rw-r--r--vendor/ramsey/collection/src/Map/AssociativeArrayMap.php3
-rw-r--r--vendor/ramsey/collection/src/Map/MapInterface.php57
-rw-r--r--vendor/ramsey/collection/src/Map/NamedParameterMap.php22
-rw-r--r--vendor/ramsey/collection/src/Map/TypedMap.php39
-rw-r--r--vendor/ramsey/collection/src/Map/TypedMapInterface.php3
7 files changed, 123 insertions, 133 deletions
diff --git a/vendor/ramsey/collection/src/Map/AbstractMap.php b/vendor/ramsey/collection/src/Map/AbstractMap.php
index ae9f2fe61..7a851a80f 100644
--- a/vendor/ramsey/collection/src/Map/AbstractMap.php
+++ b/vendor/ramsey/collection/src/Map/AbstractMap.php
@@ -16,48 +16,65 @@ 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<T>
+ * @implements MapInterface<K, 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($offset, $value): void
+ public function offsetSet(mixed $offset, mixed $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;
}
- /**
- * @inheritDoc
- */
- public function containsKey($key): bool
+ public function containsKey(int | string $key): bool
{
return array_key_exists($key, $this->data);
}
- /**
- * @inheritDoc
- */
- public function containsValue($value): bool
+ public function containsValue(mixed $value): bool
{
return in_array($value, $this->data, true);
}
@@ -71,21 +88,24 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
}
/**
- * @inheritDoc
+ * @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.
*/
- public function get($key, $defaultValue = null)
+ public function get(int | string $key, mixed $defaultValue = null): mixed
{
- if (!$this->containsKey($key)) {
- return $defaultValue;
- }
-
- return $this[$key];
+ return $this[$key] ?? $defaultValue;
}
/**
- * @inheritDoc
+ * @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`.
*/
- public function put($key, $value)
+ public function put(int | string $key, mixed $value): mixed
{
$previousValue = $this->get($key);
$this[$key] = $value;
@@ -94,9 +114,13 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
}
/**
- * @inheritDoc
+ * @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`.
*/
- public function putIfAbsent($key, $value)
+ public function putIfAbsent(int | string $key, mixed $value): mixed
{
$currentValue = $this->get($key);
@@ -108,9 +132,12 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
}
/**
- * @inheritDoc
+ * @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`.
*/
- public function remove($key)
+ public function remove(int | string $key): mixed
{
$previousValue = $this->get($key);
unset($this[$key]);
@@ -118,10 +145,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
return $previousValue;
}
- /**
- * @inheritDoc
- */
- public function removeIf($key, $value): bool
+ public function removeIf(int | string $key, mixed $value): bool
{
if ($this->get($key) === $value) {
unset($this[$key]);
@@ -133,9 +157,13 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
}
/**
- * @inheritDoc
+ * @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`.
*/
- public function replace($key, $value)
+ public function replace(int | string $key, mixed $value): mixed
{
$currentValue = $this->get($key);
@@ -146,10 +174,7 @@ abstract class AbstractMap extends AbstractArray implements MapInterface
return $currentValue;
}
- /**
- * @inheritDoc
- */
- public function replaceIf($key, $oldValue, $newValue): bool
+ public function replaceIf(int | string $key, mixed $oldValue, mixed $newValue): bool
{
if ($this->get($key) === $oldValue) {
$this[$key] = $newValue;
@@ -159,4 +184,20 @@ 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 551d2e6c6..92fdcd54c 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
+ * @template K of array-key
* @template T
- * @extends AbstractMap<T>
- * @implements TypedMapInterface<T>
+ * @extends AbstractMap<K, T>
+ * @implements TypedMapInterface<K, T>
*/
abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface
{
@@ -33,37 +33,28 @@ abstract class AbstractTypedMap extends AbstractMap implements TypedMapInterface
use ValueToStringTrait;
/**
- * @param K|null $offset
+ * @param K $offset
* @param T $value
*
* @inheritDoc
- *
* @psalm-suppress MoreSpecificImplementedParamType
*/
- public function offsetSet($offset, $value): void
+ public function offsetSet(mixed $offset, mixed $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 79a314d96..34e4e853b 100644
--- a/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php
+++ b/vendor/ramsey/collection/src/Map/AssociativeArrayMap.php
@@ -17,8 +17,7 @@ namespace Ramsey\Collection\Map;
/**
* `AssociativeArrayMap` represents a standard associative array object.
*
- * @template T
- * @extends AbstractMap<T>
+ * @extends AbstractMap<string, mixed>
*/
class AssociativeArrayMap extends AbstractMap
{
diff --git a/vendor/ramsey/collection/src/Map/MapInterface.php b/vendor/ramsey/collection/src/Map/MapInterface.php
index 6ed0b2967..22ba1bdd1 100644
--- a/vendor/ramsey/collection/src/Map/MapInterface.php
+++ b/vendor/ramsey/collection/src/Map/MapInterface.php
@@ -21,6 +21,7 @@ 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>
*/
@@ -29,9 +30,9 @@ interface MapInterface extends ArrayInterface
/**
* Returns `true` if this map contains a mapping for the specified key.
*
- * @param array-key $key The key to check in the map.
+ * @param K $key The key to check in the map.
*/
- public function containsKey($key): bool;
+ public function containsKey(int | string $key): bool;
/**
* Returns `true` if this map maps one or more keys to the specified value.
@@ -40,13 +41,12 @@ interface MapInterface extends ArrayInterface
*
* @param T $value The value to check in the map.
*/
- // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
- public function containsValue($value): bool;
+ public function containsValue(mixed $value): bool;
/**
* Return an array of the keys contained in this map.
*
- * @return list<array-key>
+ * @return list<K>
*/
public function keys(): array;
@@ -55,13 +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 array-key $key The key to return from the map.
- * @param T|null $defaultValue The default value to use if `$key` is not found.
+ * @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.
+ * @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);
+ public function get(int | string $key, mixed $defaultValue = null): mixed;
/**
* Associates the specified value with the specified key in this map.
@@ -69,14 +68,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 array-key $key The key to put or replace in the map.
+ * @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
+ * @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);
+ public function put(int | string $key, mixed $value): mixed;
/**
* Associates the specified value with the specified key in this map only if
@@ -85,25 +83,23 @@ interface MapInterface extends ArrayInterface
* If there is already a value associated with `$key`, this returns that
* value without replacing it.
*
- * @param array-key $key The key to put in the map.
+ * @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
+ * @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);
+ public function putIfAbsent(int | string $key, mixed $value): mixed;
/**
* Removes the mapping for a key from this map if it is present.
*
- * @param array-key $key The key to remove from the map.
+ * @param K $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`.
*/
- // phpcs:ignore SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
- public function remove($key);
+ public function remove(int | string $key): mixed;
/**
* Removes the entry for the specified key only if it is currently mapped to
@@ -111,26 +107,24 @@ interface MapInterface extends ArrayInterface
*
* This performs a strict type check on the value.
*
- * @param array-key $key The key to remove from the map.
+ * @param K $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;
+ public function removeIf(int | string $key, mixed $value): bool;
/**
* Replaces the entry for the specified key only if it is currently mapped
* to some value.
*
- * @param array-key $key The key to replace.
+ * @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
+ * @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);
+ public function replace(int | string $key, mixed $value): mixed;
/**
* Replaces the entry for the specified key only if currently mapped to the
@@ -138,12 +132,11 @@ interface MapInterface extends ArrayInterface
*
* This performs a strict type check on the value.
*
- * @param array-key $key The key to remove from the map.
+ * @param K $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;
+ public function replaceIf(int | string $key, mixed $oldValue, mixed $newValue): bool;
}
diff --git a/vendor/ramsey/collection/src/Map/NamedParameterMap.php b/vendor/ramsey/collection/src/Map/NamedParameterMap.php
index 9926ddd8c..f948e476c 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<mixed>
+ * @extends AbstractMap<string, mixed>
*/
class NamedParameterMap extends AbstractMap
{
@@ -38,13 +38,13 @@ class NamedParameterMap extends AbstractMap
*
* @var array<string, string>
*/
- protected $namedParameters;
+ private readonly array $namedParameters;
/**
* Constructs a new `NamedParameterMap`.
*
* @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.
+ * @param array<string, mixed> $data An initial set of data to set on this map.
*/
public function __construct(array $namedParameters, array $data = [])
{
@@ -62,22 +62,12 @@ class NamedParameterMap extends AbstractMap
return $this->namedParameters;
}
- /**
- * @inheritDoc
- */
- public function offsetSet($offset, $value): void
+ public function offsetSet(mixed $offset, mixed $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 \''
- . $offset . '\''
+ . $this->toolValueToString($offset) . '\'',
);
}
@@ -85,7 +75,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 2e796377a..f914d9c70 100644
--- a/vendor/ramsey/collection/src/Map/TypedMap.php
+++ b/vendor/ramsey/collection/src/Map/TypedMap.php
@@ -14,13 +14,11 @@ 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
@@ -80,34 +78,12 @@ use Ramsey\Collection\Tool\TypeTrait;
* }
* ```
*
- * @template K
+ * @template K of array-key
* @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.
@@ -116,12 +92,11 @@ 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(string $keyType, string $valueType, array $data = [])
- {
- $this->keyType = $keyType;
- $this->valueType = $valueType;
-
- /** @psalm-suppress MixedArgumentTypeCoercion */
+ public function __construct(
+ private readonly string $keyType,
+ private readonly string $valueType,
+ array $data = [],
+ ) {
parent::__construct($data);
}
diff --git a/vendor/ramsey/collection/src/Map/TypedMapInterface.php b/vendor/ramsey/collection/src/Map/TypedMapInterface.php
index 0308109cc..5a44f0647 100644
--- a/vendor/ramsey/collection/src/Map/TypedMapInterface.php
+++ b/vendor/ramsey/collection/src/Map/TypedMapInterface.php
@@ -18,8 +18,9 @@ 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<T>
+ * @extends MapInterface<K, T>
*/
interface TypedMapInterface extends MapInterface
{