Skip to content

Commit 3e27947

Browse files
committed
Use InvalidArgumentException
1 parent cc04632 commit 3e27947

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/Filterer.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TraderInteractive;
44

55
use Exception;
6+
use InvalidArgumentException;
67
use Throwable;
78
use TraderInteractive\Exceptions\FilterException;
89

@@ -110,11 +111,11 @@ final class Filterer
110111
* on error [false, null, 'error message', array of unknown fields]
111112
*
112113
* @throws Exception
113-
* @throws \InvalidArgumentException if 'allowUnknowns' option was not a bool
114-
* @throws \InvalidArgumentException if 'defaultRequired' option was not a bool
115-
* @throws \InvalidArgumentException if filters for a field was not a array
116-
* @throws \InvalidArgumentException if a filter for a field was not a array
117-
* @throws \InvalidArgumentException if 'required' for a field was not a bool
114+
* @throws InvalidArgumentException if 'allowUnknowns' option was not a bool
115+
* @throws InvalidArgumentException if 'defaultRequired' option was not a bool
116+
* @throws InvalidArgumentException if filters for a field was not an array
117+
* @throws InvalidArgumentException if a filter for a field was not an array
118+
* @throws InvalidArgumentException if 'required' for a field was not a bool
118119
*/
119120
public static function filter(array $spec, array $input, array $options = []) : array
120121
{
@@ -319,7 +320,7 @@ public static function ofArray(array $value, array $spec) : array
319320
private static function assertIfStringOrInt($alias)
320321
{
321322
if (!is_string($alias) && !is_int($alias)) {
322-
throw new \InvalidArgumentException('$alias was not a string or int');
323+
throw new InvalidArgumentException('$alias was not a string or int');
323324
}
324325
}
325326

@@ -360,7 +361,7 @@ private static function getRequired($filters, $defaultRequired, $field) : bool
360361
{
361362
$required = isset($filters['required']) ? $filters['required'] : $defaultRequired;
362363
if ($required !== false && $required !== true) {
363-
throw new \InvalidArgumentException("'required' for field '{$field}' was not a bool");
364+
throw new InvalidArgumentException("'required' for field '{$field}' was not a bool");
364365
}
365366

366367
return $required;
@@ -369,7 +370,7 @@ private static function getRequired($filters, $defaultRequired, $field) : bool
369370
private static function assertFiltersIsAnArray($filters, string $field)
370371
{
371372
if (!is_array($filters)) {
372-
throw new \InvalidArgumentException("filters for field '{$field}' was not a array");
373+
throw new InvalidArgumentException("filters for field '{$field}' was not a array");
373374
}
374375
}
375376

@@ -414,7 +415,7 @@ private static function handleFilterAliases($function)
414415
private static function assertFilterIsNotArray($filter, string $field)
415416
{
416417
if (!is_array($filter)) {
417-
throw new \InvalidArgumentException("filter for field '{$field}' was not a array");
418+
throw new InvalidArgumentException("filter for field '{$field}' was not a array");
418419
}
419420
}
420421

@@ -424,7 +425,7 @@ private static function validateCustomError(array &$filters, string $field)
424425
if (array_key_exists('error', $filters)) {
425426
$customError = $filters['error'];
426427
if (!is_string($customError) || trim($customError) === '') {
427-
throw new \InvalidArgumentException("error for field '{$field}' was not a non-empty string");
428+
throw new InvalidArgumentException("error for field '{$field}' was not a non-empty string");
428429
}
429430

430431
unset($filters['error']);//unset so its not used as a filter
@@ -437,7 +438,7 @@ private static function getAllowUnknowns(array $options) : bool
437438
{
438439
$allowUnknowns = $options['allowUnknowns'];
439440
if ($allowUnknowns !== false && $allowUnknowns !== true) {
440-
throw new \InvalidArgumentException("'allowUnknowns' option was not a bool");
441+
throw new InvalidArgumentException("'allowUnknowns' option was not a bool");
441442
}
442443

443444
return $allowUnknowns;
@@ -447,7 +448,7 @@ private static function getDefaultRequired(array $options) : bool
447448
{
448449
$defaultRequired = $options['defaultRequired'];
449450
if ($defaultRequired !== false && $defaultRequired !== true) {
450-
throw new \InvalidArgumentException("'defaultRequired' option was not a bool");
451+
throw new InvalidArgumentException("'defaultRequired' option was not a bool");
451452
}
452453

453454
return $defaultRequired;

0 commit comments

Comments
 (0)