diff --git a/src/Assert.php b/src/Assert.php index 20116cc1..cdb176f8 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1857,6 +1857,22 @@ public static function keyExists(mixed $array, string|int $key, string $message return $array; } + /** + * @psalm-pure + * + * @param list $keys + * + * @throws InvalidArgumentException + */ + public static function KeysExist(mixed $array, array $keys, string $message = ''): void + { + static::isArray($array); + + foreach ($keys as $key) { + static::keyExists($array, $key, $message ?: 'Expected the key %s to exist.',); + } + } + /** * @psalm-pure * diff --git a/src/Mixin.php b/src/Mixin.php index ad0aeec8..6100ae66 100644 --- a/src/Mixin.php +++ b/src/Mixin.php @@ -4490,6 +4490,62 @@ public static function allNullOrKeyExists(mixed $array, string|int $key, string return $array; } + /** + * @psalm-pure + * + * @param list $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 $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 $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 *