Skip to content

Commit

Permalink
add containsKey alias
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmmfp committed Aug 30, 2024
1 parent ce10be4 commit def70e0
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Psl/Collection/IndexAccessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Psl/Collection/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Psl/Collection/MutableMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Psl/Collection/MutableSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Psl/Collection/MutableVector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Psl/Collection/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Psl/Collection/Vector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Collection/MutableMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Collection/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit def70e0

Please sign in to comment.