diff --git a/BaseValidator.php b/BaseValidator.php index 444dc9e..6ba961a 100644 --- a/BaseValidator.php +++ b/BaseValidator.php @@ -34,18 +34,13 @@ abstract class BaseValidator /** - * @param $field - * @param $message + * @param string $field + * @param string $message * @return bool */ - public function addError($field, $message): bool + public function addError(string $field, string $message): bool { - if (!is_null($field)) { - $message = str_replace(':attribute', $field, $message); - } - - $this->message = $message; - + $this->message = str_replace(':attribute', $field, $message); return false; } diff --git a/DateTimeValidator.php b/DateTimeValidator.php index 1b65186..b44eac3 100644 --- a/DateTimeValidator.php +++ b/DateTimeValidator.php @@ -38,46 +38,46 @@ class DateTimeValidator extends BaseValidator } /** - * @param $value + * @param string $value * @return bool * * 效验分秒 格式如 01:02 or 01-02 */ - public function validatorTime($value): bool + public function validatorTime(string $value): bool { return (bool)preg_match('/^\d{2}:\d{2}(:\d{2})?+(\.\d+)?$/', $value); } /** - * @param $value + * @param string $value * @return bool * * 效验分秒 格式如 2017-12-22 01:02 */ - public function validateDatetime($value): bool + public function validateDatetime(string $value): bool { return (bool)preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?+(\.\d+)?$/', $value); } /** - * @param $value + * @param string $value * @return bool * * 效验分秒 格式如 2017-12-22 */ - public function validatorDate($value): bool + public function validatorDate(string $value): bool { return (bool)preg_match('/^\d{4}-\d{2}-\d{2}$/', $value); } /** - * @param $value + * @param string|int $value * @return bool * * 效验时间戳 格式如 1521452254 */ - public function validatorTimestamp($value): bool + public function validatorTimestamp(string|int $value): bool { return (bool)preg_match('/^1\d{9}$/', $value); } diff --git a/Validator.php b/Validator.php index bfaaf19..49021af 100644 --- a/Validator.php +++ b/Validator.php @@ -92,6 +92,7 @@ class Validator extends BaseValidator return [Kiri::createObject($defined), 'trigger']; } + /** * @param ModelInterface $model * @return bool