From eb5f9a90e7037d2a6a9ced862055f611fefdcf26 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Mon, 25 Mar 2024 08:31:13 +0100 Subject: [PATCH] Update the validation engine of age-related rules Signed-off-by: Henrique Moody --- library/Rules/AbstractAge.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/library/Rules/AbstractAge.php b/library/Rules/AbstractAge.php index 0e43ba380..2c0ca92a6 100644 --- a/library/Rules/AbstractAge.php +++ b/library/Rules/AbstractAge.php @@ -10,6 +10,8 @@ namespace Respect\Validation\Rules; use Respect\Validation\Helpers\CanValidateDateTime; +use Respect\Validation\Result; +use Respect\Validation\Rules\Core\Standard; use function date; use function date_parse_from_format; @@ -17,7 +19,7 @@ use function strtotime; use function vsprintf; -abstract class AbstractAge extends AbstractRule +abstract class AbstractAge extends Standard { use CanValidateDateTime; @@ -32,25 +34,18 @@ public function __construct( $this->baseDate = (int) date('Ymd') - $this->age * 10000; } - public function validate(mixed $input): bool + public function evaluate(mixed $input): Result { + $parameters = ['age' => $this->age]; if (!is_scalar($input)) { - return false; + return Result::failed($input, $this, $parameters); } if ($this->format === null) { - return $this->isValidWithoutFormat((string) $input); + return new Result($this->isValidWithoutFormat((string) $input), $input, $this, $parameters); } - return $this->isValidWithFormat($this->format, (string) $input); - } - - /** - * @return array - */ - public function getParams(): array - { - return ['age' => $this->age]; + return new Result($this->isValidWithFormat($this->format, (string) $input), $input, $this, $parameters); } private function isValidWithoutFormat(string $dateTime): bool