From 5a5b5adf3f3a732497d07ac232d10ec76a754d87 Mon Sep 17 00:00:00 2001 From: sadeesh-sdet Date: Thu, 16 Nov 2023 20:10:10 +0530 Subject: [PATCH] Refactor: Renamed isListOfStrings function to isArrayOfStrings and used built-in InvalidArgumentException class --- src/Exception/InvalidArgumentException.php | 10 ---------- src/Test/DefaultTest.php | 12 ++++++------ 2 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 src/Exception/InvalidArgumentException.php diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php deleted file mode 100644 index 260b4f7..0000000 --- a/src/Exception/InvalidArgumentException.php +++ /dev/null @@ -1,10 +0,0 @@ -isListOfStrings($data[$key])) { + if (!is_array($data[$key]) || !$this->isArrayOfStrings($data[$key])) { throw new InvalidArgumentException("Data structure is not as expected."); } @@ -96,18 +96,18 @@ private function issetField(array $data, array $fields): bool } /** - * Checks if an array contains a list of strings. + * Checks if an iterable value is an array containing only strings. * * @param iterable $value * The array to check. * * @return bool - * Returns `true` if the array contains a list of strings, `false` otherwise. + * Returns `true` if the iterable value is an array containing only strings, `false` otherwise. * * @throws InvalidArgumentException - * If the input value is not an array. + * If the input value is not an array or contains non-string elements.. */ - private function isListOfStrings(iterable $value): bool + private function isArrayOfStrings(iterable $value): bool { if (!is_array($value)) { throw new InvalidArgumentException("Input must be an array.");