From b0fd14cd71d60c1b9926aff10fe9e8eeebe1285c Mon Sep 17 00:00:00 2001 From: Asko Nomm Date: Tue, 22 Feb 2022 21:32:37 +0100 Subject: Lots of documentation and basic tests --- src/Validators/RequiredValidator.php | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Validators/RequiredValidator.php (limited to 'src/Validators/RequiredValidator.php') diff --git a/src/Validators/RequiredValidator.php b/src/Validators/RequiredValidator.php new file mode 100644 index 0000000..4cf6bfc --- /dev/null +++ b/src/Validators/RequiredValidator.php @@ -0,0 +1,37 @@ + + */ +class RequiredValidator implements Validator +{ + /** + * Returns a boolean `true` when given `$value` is present + * and not empty. Returns `false` otherwise. + * + * @param string $value + * @param mixed $modifier + * @return boolean + */ + public static function validate(string $value, mixed $modifier = null): bool + { + return isset($value) && $value !== ''; + } + + /** + * Composes the error message in case the validation fails. + * + * @param string $field + * @param mixed $modifier + * @return string + */ + public static function composeError(string $field, mixed $modifier = null): string + { + return "${field} is required."; + } +} -- cgit v1.2.3