Skip to content

Commit

Permalink
Refactor: Renamed isListOfStrings function to isArrayOfStrings and us…
Browse files Browse the repository at this point in the history
…ed built-in InvalidArgumentException class
  • Loading branch information
sadeesh-sdet committed Nov 16, 2023
1 parent 781d401 commit 5a5b5ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
10 changes: 0 additions & 10 deletions src/Exception/InvalidArgumentException.php

This file was deleted.

12 changes: 6 additions & 6 deletions src/Test/DefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Mdtt\Exception\ExecutionException;
use PHPUnit\Framework\Assert;
use Mdtt\Exception\InvalidArgumentException;
use InvalidArgumentException;

class DefaultTest extends Test
{
Expand Down Expand Up @@ -87,7 +87,7 @@ private function issetField(array $data, array $fields): bool
}

// Make sure that the key value is an array of strings
if (!is_array($data[$key]) || !$this->isListOfStrings($data[$key])) {
if (!is_array($data[$key]) || !$this->isArrayOfStrings($data[$key])) {
throw new InvalidArgumentException("Data structure is not as expected.");
}

Expand All @@ -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<string> $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.");
Expand Down

0 comments on commit 5a5b5ad

Please sign in to comment.