diff --git a/src/Rules/VatNumber.php b/src/Rules/VatNumber.php index e757df4..df8cddd 100755 --- a/src/Rules/VatNumber.php +++ b/src/Rules/VatNumber.php @@ -7,9 +7,14 @@ class VatNumber implements ValidationRule { + public function isValid(mixed $value): bool + { + return VatValidator::validate($value); + } + public function validate(string $attribute, mixed $value, \Closure $fail): void { - if (! VatValidator::validate($value)) { + if (! $this->isValid($value)) { $fail(__('The :attribute must be a valid VAT number.')); } } diff --git a/src/Rules/VatNumberExist.php b/src/Rules/VatNumberExist.php index e22fb33..ee5a775 100755 --- a/src/Rules/VatNumberExist.php +++ b/src/Rules/VatNumberExist.php @@ -8,9 +8,14 @@ class VatNumberExist implements ValidationRule { + public function isValid(mixed $value): bool + { + return VatValidator::validateExistence($value); + } + public function validate(string $attribute, mixed $value, Closure $fail): void { - if (! VatValidator::validateExistence($value)) { + if (! $this->isValid($value)) { $fail(__('VAT number :attribute not exist.')); } } diff --git a/src/Rules/VatNumberFormat.php b/src/Rules/VatNumberFormat.php index 221207e..ee91a64 100755 --- a/src/Rules/VatNumberFormat.php +++ b/src/Rules/VatNumberFormat.php @@ -7,9 +7,14 @@ class VatNumberFormat implements ValidationRule { + public function isValid(mixed $value): bool + { + return VatValidator::validateFormat($value); + } + public function validate(string $attribute, mixed $value, \Closure $fail): void { - if (! VatValidator::validateFormat($value)) { + if (! $this->isValid($value)) { $fail(__('The :attribute must be write in a valid number format {country_name}{vat_number}.')); } } diff --git a/src/VatValidatorServiceProvider.php b/src/VatValidatorServiceProvider.php index 0b10a1d..6423d7c 100644 --- a/src/VatValidatorServiceProvider.php +++ b/src/VatValidatorServiceProvider.php @@ -19,25 +19,25 @@ public function boot(): void /** * Register the "vat_number" validation rule. */ - Validator::extend('vat_number', static function ($attribute, $value, $parameters, $validator): void { + Validator::extend('vat_number', static function ($attribute, $value, $parameters, $validator): bool { $rule = new VatNumber(); - $rule->validate($attribute, $value, static fn (string $message = null): null => null); + return $rule->isValid($value); }); /** * Register the "vat_number_exist" validation rule. */ - Validator::extend('vat_number_exist', static function ($attribute, $value, $parameters, $validator): void { + Validator::extend('vat_number_exist', static function ($attribute, $value, $parameters, $validator): bool { $rule = new VatNumberExist(); - $rule->validate($attribute, $value, static fn (string $message = null): null => null); + return $rule->isValid($value); }); /** * Register the "vat_number_format" validation rule. */ - Validator::extend('vat_number_format', static function ($attribute, $value, $parameters, $validator): void { + Validator::extend('vat_number_format', static function ($attribute, $value, $parameters, $validator): bool { $rule = new VatNumberFormat(); - $rule->validate($attribute, $value, static fn (string $message = null): null => null); + return $rule->isValid($value); }); }