@@ -127,8 +127,8 @@ public function execute(array $input) : FilterResponse
127127 $ filters = $ this ->specification [$ field ];
128128 self ::assertFiltersIsAnArray ($ filters , $ field );
129129 $ customError = self ::validateCustomError ($ filters , $ field );
130- unset($ filters [' required ' ]);//doesn't matter if required since we have this one
131- unset($ filters [' default ' ]);//doesn't matter if there is a default since we have a value
130+ unset($ filters [FilterOptions:: IS_REQUIRED ]);//doesn't matter if required since we have this one
131+ unset($ filters [FilterOptions:: DEFAULT_VALUE ]);//doesn't matter if there is a default since we have a value
132132 foreach ($ filters as $ filter ) {
133133 self ::assertFilterIsNotArray ($ filter , $ field );
134134
@@ -156,8 +156,8 @@ public function execute(array $input) : FilterResponse
156156 foreach ($ leftOverSpec as $ field => $ filters ) {
157157 self ::assertFiltersIsAnArray ($ filters , $ field );
158158 $ required = self ::getRequired ($ filters , $ this ->defaultRequired , $ field );
159- if (array_key_exists (' default ' , $ filters )) {
160- $ inputToFilter [$ field ] = $ filters [' default ' ];
159+ if (array_key_exists (FilterOptions:: DEFAULT_VALUE , $ filters )) {
160+ $ inputToFilter [$ field ] = $ filters [FilterOptions:: DEFAULT_VALUE ];
161161 continue ;
162162 }
163163
@@ -484,9 +484,11 @@ private static function handleRequiredFields(bool $required, string $field, arra
484484
485485 private static function getRequired ($ filters , $ defaultRequired , $ field ) : bool
486486 {
487- $ required = isset ( $ filters [' required ' ]) ? $ filters [ ' required ' ] : $ defaultRequired ;
487+ $ required = $ filters [FilterOptions:: IS_REQUIRED ] ?? $ defaultRequired ;
488488 if ($ required !== false && $ required !== true ) {
489- throw new InvalidArgumentException ("'required' for field ' {$ field }' was not a bool " );
489+ throw new InvalidArgumentException (
490+ sprintf ("'%s' for field '%s' was not a bool " , FilterOptions::IS_REQUIRED , $ field )
491+ );
490492 }
491493
492494 return $ required ;
@@ -547,13 +549,15 @@ private static function assertFilterIsNotArray($filter, string $field)
547549 private static function validateCustomError (array &$ filters , string $ field )
548550 {
549551 $ customError = null ;
550- if (array_key_exists (' error ' , $ filters )) {
551- $ customError = $ filters [' error ' ];
552+ if (array_key_exists (FilterOptions:: CUSTOM_ERROR , $ filters )) {
553+ $ customError = $ filters [FilterOptions:: CUSTOM_ERROR ];
552554 if (!is_string ($ customError ) || trim ($ customError ) === '' ) {
553- throw new InvalidArgumentException ("error for field ' {$ field }' was not a non-empty string " );
555+ throw new InvalidArgumentException (
556+ sprintf ("%s for field '%s' was not a non-empty string " , FilterOptions::CUSTOM_ERROR , $ field )
557+ );
554558 }
555559
556- unset($ filters [' error ' ]);//unset so its not used as a filter
560+ unset($ filters [FilterOptions:: CUSTOM_ERROR ]);//unset so its not used as a filter
557561 }
558562
559563 return $ customError ;
0 commit comments