aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/collection/src/Map/AbstractMap.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-14 09:35:09 +0000
committerMario <mario@mariovavti.com>2024-03-14 09:35:09 +0000
commit6bf61dfa6b585db01b607a79bd64ec9c583a9c10 (patch)
tree78698101aa58d918568dfc0020650fc337e8d3e0 /vendor/ramsey/collection/src/Map/AbstractMap.php
parent0e59cfb8390e4c6aee29ef73b53a4dc6b7fb581e (diff)
downloadvolse-hubzilla-6bf61dfa6b585db01b607a79bd64ec9c583a9c10.tar.gz
volse-hubzilla-6bf61dfa6b585db01b607a79bd64ec9c583a9c10.tar.bz2
volse-hubzilla-6bf61dfa6b585db01b607a79bd64ec9c583a9c10.zip
composer update and use the fixed streams php-jcs library until the floats issue will be fixed upstream. see here for reference https://codeberg.org/streams/streams/issues/151
Diffstat (limited to 'vendor/ramsey/collection/src/Map/AbstractMap.php')
-rw-r--r--vendor/ramsey/collection/src/Map/AbstractMap.php109
1 files changed, 75 insertions, 34 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();
+ }
}