Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,22 @@ public static function keyExists(mixed $array, string|int $key, string $message
return $array;
}

/**
* @psalm-pure
*
* @param list<int|string> $keys
*
* @throws InvalidArgumentException
*/
public static function KeysExist(mixed $array, array $keys, string $message = ''): void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be camelCase, keysExist.

{
static::isArray($array);

foreach ($keys as $key) {
static::keyExists($array, $key, $message ?: 'Expected the key %s to exist.',);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static::keyExists($array, $key, $message ?: 'Expected the key %s to exist.',);
static::keyExists($array, $key, $message);

}
}

/**
* @psalm-pure
*
Expand Down
56 changes: 56 additions & 0 deletions src/Mixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4490,6 +4490,62 @@ public static function allNullOrKeyExists(mixed $array, string|int $key, string
return $array;
}

/**
* @psalm-pure
*
* @param list<int|string> $keys
*
* @return mixed
*
* @throws InvalidArgumentException
*/
public static function nullOrKeysExist(mixed $array, array $keys, string $message = ''): mixed
{
null === $array || static::KeysExist($array, $keys, $message);

return $array;
}

/**
* @psalm-pure
*
* @param list<int|string> $keys
*
* @return mixed
*
* @throws InvalidArgumentException
*/
public static function allKeysExist(mixed $array, array $keys, string $message = ''): mixed
{
static::isIterable($array);

foreach ($array as $entry) {
static::KeysExist($entry, $keys, $message);
}

return $array;
}

/**
* @psalm-pure
*
* @param list<int|string> $keys
*
* @return mixed
*
* @throws InvalidArgumentException
*/
public static function allNullOrKeysExist(mixed $array, array $keys, string $message = ''): mixed
{
static::isIterable($array);

foreach ($array as $entry) {
null === $entry || static::KeysExist($entry, $keys, $message);
}

return $array;
}

/**
* @psalm-pure
*
Expand Down
Loading