From 326a9793028d537bf8575bea1e04d94a67679874 Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Tue, 6 Aug 2019 09:02:03 +1000 Subject: [PATCH] Minor improvement to logic in AbstractInputHandler::validateInput(). Ensures that an input with a validator, but with a default value and no user suplied input, will have the default value used. --- src/Input/AbstractInputHandler.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Input/AbstractInputHandler.php b/src/Input/AbstractInputHandler.php index 97413e0..e0c5e13 100644 --- a/src/Input/AbstractInputHandler.php +++ b/src/Input/AbstractInputHandler.php @@ -68,17 +68,17 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface if(!Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_REQUIRED)) { self::checkRequiredAndRequiredValue($input, $this->input); } - // There is a default value, input has not been set, and there - // is no validator + // There is a default value and input has not been set. Assign the + // default value to the result. if ( null !== $input->default() && - null === $this->find($input->name()) && - null === $input->validator() + null === $this->find($input->name()) ) { $result = $input->default(); - // Input has been set and it has a validator. Skip this if - // FLAG_VALIDATION_SKIP_CUSTOM is set + // Input has been set AND it has a validator. Run the validator over the + // input. Note, this will be skipped if FLAG_VALIDATION_SKIP_CUSTOM is + // set } elseif (null !== $this->find($input->name()) && null !== $input->validator() && !Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_CUSTOM)) { $validator = $input->validator(); @@ -94,7 +94,8 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface throw new Exceptions\InputValidationFailedException($input, 0, $ex); } - // No default, no validator, but may or may not have been set + // No default, but may or may not have been set so assign whatever value + // it might have to the result } else { $result = $this->find($input->name()); }