Skip to content

Commit d8c2b4f

Browse files
committed
Use FiltererOptions in Filterer
1 parent 7a02dd4 commit d8c2b4f

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/Filterer.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ final class Filterer implements FiltererInterface
4646
* @var array
4747
*/
4848
const DEFAULT_OPTIONS = [
49-
'allowUnknowns' => false,
50-
'defaultRequired' => false,
51-
'responseType' => self::RESPONSE_TYPE_ARRAY,
49+
FiltererOptions::ALLOW_UNKNOWNS => false,
50+
FiltererOptions::DEFAULT_REQUIRED => false,
51+
FiltererOptions::RESPONSE_TYPE => self::RESPONSE_TYPE_ARRAY,
5252
];
5353

5454
/**
@@ -219,8 +219,8 @@ public function withSpecification(array $specification) : FiltererInterface
219219
private function getOptions() : array
220220
{
221221
return [
222-
'defaultRequired' => $this->defaultRequired,
223-
'allowUnknowns' => $this->allowUnknowns,
222+
FiltererOptions::DEFAULT_REQUIRED => $this->defaultRequired,
223+
FiltererOptions::ALLOW_UNKNOWNS => $this->allowUnknowns,
224224
];
225225
}
226226

@@ -296,7 +296,7 @@ private function getOptions() : array
296296
public static function filter(array $specification, array $input, array $options = [])
297297
{
298298
$options += self::DEFAULT_OPTIONS;
299-
$responseType = $options['responseType'];
299+
$responseType = $options[FiltererOptions::RESPONSE_TYPE];
300300

301301
$filterer = new Filterer($specification, $options);
302302
$filterResponse = $filterer->execute($input);
@@ -561,19 +561,21 @@ private static function validateCustomError(array &$filters, string $field)
561561

562562
private static function getAllowUnknowns(array $options) : bool
563563
{
564-
$allowUnknowns = $options['allowUnknowns'];
564+
$allowUnknowns = $options[FiltererOptions::ALLOW_UNKNOWNS];
565565
if ($allowUnknowns !== false && $allowUnknowns !== true) {
566-
throw new InvalidArgumentException("'allowUnknowns' option was not a bool");
566+
throw new InvalidArgumentException(sprintf("'%s' option was not a bool", FiltererOptions::ALLOW_UNKNOWNS));
567567
}
568568

569569
return $allowUnknowns;
570570
}
571571

572572
private static function getDefaultRequired(array $options) : bool
573573
{
574-
$defaultRequired = $options['defaultRequired'];
574+
$defaultRequired = $options[FiltererOptions::DEFAULT_REQUIRED];
575575
if ($defaultRequired !== false && $defaultRequired !== true) {
576-
throw new InvalidArgumentException("'defaultRequired' option was not a bool");
576+
throw new InvalidArgumentException(
577+
sprintf("'%s' option was not a bool", FiltererOptions::DEFAULT_REQUIRED)
578+
);
577579
}
578580

579581
return $defaultRequired;
@@ -602,6 +604,6 @@ private static function generateFilterResponse(string $responseType, FilterRespo
602604
];
603605
}
604606

605-
throw new InvalidArgumentException("'responseType' was not a recognized value");
607+
throw new InvalidArgumentException(sprintf("'%s' was not a recognized value", FiltererOptions::RESPONSE_TYPE));
606608
}
607609
}

0 commit comments

Comments
 (0)