diff --git a/src/Psl/Collection/IndexAccessInterface.php b/src/Psl/Collection/IndexAccessInterface.php index 797d23cd..25940b84 100644 --- a/src/Psl/Collection/IndexAccessInterface.php +++ b/src/Psl/Collection/IndexAccessInterface.php @@ -34,6 +34,17 @@ public function at(int|string $k): mixed; */ public function contains(int|string $k): bool; + /** + * Alias of `contains`. + * + * @param Tk $k + * + * @see contains() method + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool; + /** * Returns the value at the specified key in the current collection. * diff --git a/src/Psl/Collection/Map.php b/src/Psl/Collection/Map.php index a4abb6ff..3f486fe6 100644 --- a/src/Psl/Collection/Map.php +++ b/src/Psl/Collection/Map.php @@ -253,6 +253,18 @@ public function contains(int|string $k): bool return array_key_exists($k, $this->elements); } + /** + * Alias of `contains`. + * + * @param Tk $k + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool + { + return $this->contains($k); + } + /** * Returns the value at the specified key in the current map. * diff --git a/src/Psl/Collection/MutableMap.php b/src/Psl/Collection/MutableMap.php index 12a4d102..7dd1d252 100644 --- a/src/Psl/Collection/MutableMap.php +++ b/src/Psl/Collection/MutableMap.php @@ -253,6 +253,18 @@ public function contains(int|string $k): bool return array_key_exists($k, $this->elements); } + /** + * Alias of `contains`. + * + * @param Tk $k + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool + { + return $this->contains($k); + } + /** * Returns the value at the specified key in the current map. * diff --git a/src/Psl/Collection/MutableSet.php b/src/Psl/Collection/MutableSet.php index f58c12bd..21eda1f6 100644 --- a/src/Psl/Collection/MutableSet.php +++ b/src/Psl/Collection/MutableSet.php @@ -233,6 +233,20 @@ public function contains(int|string $k): bool return array_key_exists($k, $this->elements); } + /** + * Alias of `contains`. + * + * @param T $k + * + * @return bool True if the value is in the set, false otherwise. + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool + { + return $this->contains($k); + } + /** * Returns the provided value if it is part of the set, or null if it is not. * diff --git a/src/Psl/Collection/MutableVector.php b/src/Psl/Collection/MutableVector.php index 26c465f0..76915ca0 100644 --- a/src/Psl/Collection/MutableVector.php +++ b/src/Psl/Collection/MutableVector.php @@ -204,6 +204,18 @@ public function contains(int|string $k): bool return array_key_exists($k, $this->elements); } + /** + * Alias of `contains`. + * + * @param int<0, max> $k + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool + { + return $this->contains($k); + } + /** * Returns the value at the specified key in the current `MutableVector`. * diff --git a/src/Psl/Collection/Set.php b/src/Psl/Collection/Set.php index 5d91a514..981b4785 100644 --- a/src/Psl/Collection/Set.php +++ b/src/Psl/Collection/Set.php @@ -236,6 +236,20 @@ public function contains(int|string $k): bool return array_key_exists($k, $this->elements); } + /** + * Alias of `contains`. + * + * @param T $k + * + * @return bool True if the value is in the set, false otherwise. + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool + { + return $this->contains($k); + } + /** * Returns the provided value if it is part of the set, or null if it is not. * diff --git a/src/Psl/Collection/Vector.php b/src/Psl/Collection/Vector.php index 964c14c4..1f4e9ba7 100644 --- a/src/Psl/Collection/Vector.php +++ b/src/Psl/Collection/Vector.php @@ -204,6 +204,18 @@ public function contains(int|string $k): bool return array_key_exists($k, $this->elements); } + /** + * Alias of `contains`. + * + * @param int<0, max> $k + * + * @psalm-mutation-free + */ + public function containsKey(int|string $k): bool + { + return $this->contains($k); + } + /** * Returns the value at the specified key in the current `Vector`. * diff --git a/tests/unit/Collection/MutableMapTest.php b/tests/unit/Collection/MutableMapTest.php index fce753be..df2ae468 100644 --- a/tests/unit/Collection/MutableMapTest.php +++ b/tests/unit/Collection/MutableMapTest.php @@ -235,7 +235,8 @@ public function testOffsetGetThrowsForInvalidOffsetType(): void $map[false]; } - public function testFromItems(): void { + public function testFromItems(): void + { $map = MutableMap::fromItems([ 'foo' => 'bar', 'bar' => 'baz', diff --git a/tests/unit/Collection/SetTest.php b/tests/unit/Collection/SetTest.php index 2c2bef72..015f5a7c 100644 --- a/tests/unit/Collection/SetTest.php +++ b/tests/unit/Collection/SetTest.php @@ -15,7 +15,8 @@ final class SetTest extends AbstractSetTest */ protected string $setClass = Set::class; - public function testFromItems(): void { + public function testFromItems(): void + { $set = Set::fromItems([ 'foo', 'bar',