diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d474c9e0..11c21352 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,16 @@ - - - - - ./tests/ - - - - - src/ - - - - - + + + + ./tests/ + + + + + + + + src/ + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 00000000..d474c9e0 --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,29 @@ + + + + + + ./tests/ + + + + + src/ + + + + + + diff --git a/src/LaravelValidateServiceProvider.php b/src/LaravelValidateServiceProvider.php index 24cd1c47..f61aad6e 100644 --- a/src/LaravelValidateServiceProvider.php +++ b/src/LaravelValidateServiceProvider.php @@ -40,10 +40,8 @@ class LaravelValidateServiceProvider extends ServiceProvider /** * Register files. - * - * @return void */ - public function register() + public function register(): void { if ($this->app->runningInConsole()) { $this->publishLangFiles(); @@ -68,10 +66,8 @@ private function publishLangFiles(): void /** * Publish config file. - * - * @return void */ - private function publishConfigFile() + private function publishConfigFile(): void { $this->publishes([ __DIR__.'/../config/laravel-validate.php' => config_path('laravel-validate.php'), diff --git a/src/Rules/ValidBase64.php b/src/Rules/ValidBase64.php index 460e53cd..c30f8a5f 100644 --- a/src/Rules/ValidBase64.php +++ b/src/Rules/ValidBase64.php @@ -8,22 +8,16 @@ class ValidBase64 implements Rule { /** * Check base64. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return base64_encode(base64_decode($value, true)) === $value; } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.base64'); } diff --git a/src/Rules/ValidBitcoinAddress.php b/src/Rules/ValidBitcoinAddress.php index 7be9a626..ce2bbfcd 100644 --- a/src/Rules/ValidBitcoinAddress.php +++ b/src/Rules/ValidBitcoinAddress.php @@ -7,23 +7,17 @@ class ValidBitcoinAddress implements Rule { /** - * Check bitcoin address. - * - * @param string $attribute - * @param mixed $value - * @return bool + * Check bitcoin address is valid. */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?:bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.bitcoin-address'); } diff --git a/src/Rules/ValidCamelCase.php b/src/Rules/ValidCamelCase.php index 5c92d9ac..4c84c9d2 100644 --- a/src/Rules/ValidCamelCase.php +++ b/src/Rules/ValidCamelCase.php @@ -8,22 +8,16 @@ class ValidCamelCase implements Rule { /** * Check value is camel case. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?:\p{Lu}?\p{Ll}+)(?:\p{Lu}\p{Ll}+)*$/u', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.camel-case'); } diff --git a/src/Rules/ValidCapitalCharWithNumber.php b/src/Rules/ValidCapitalCharWithNumber.php index dd1e26b3..eced946f 100644 --- a/src/Rules/ValidCapitalCharWithNumber.php +++ b/src/Rules/ValidCapitalCharWithNumber.php @@ -8,22 +8,16 @@ class ValidCapitalCharWithNumber implements Rule { /** * Check all words are capital & with hyphen & number. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/[A-Z]{2,}-\d+/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.capital-char-with-number'); } diff --git a/src/Rules/ValidCarNumber.php b/src/Rules/ValidCarNumber.php index 6aed527f..7c4c532d 100644 --- a/src/Rules/ValidCarNumber.php +++ b/src/Rules/ValidCarNumber.php @@ -8,22 +8,16 @@ class ValidCarNumber implements Rule { /** * Check car number is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^[A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{4}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.car-number'); } diff --git a/src/Rules/ValidCartNumberIran.php b/src/Rules/ValidCartNumberIran.php index 74fa388c..78971a59 100644 --- a/src/Rules/ValidCartNumberIran.php +++ b/src/Rules/ValidCartNumberIran.php @@ -8,12 +8,8 @@ class ValidCartNumberIran implements Rule { /** * Check cart number is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { $cardToArr = str_split($value); $cardTotal = 0; @@ -31,10 +27,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.cart-number-iran'); } diff --git a/src/Rules/ValidCreditCard.php b/src/Rules/ValidCreditCard.php index 684826f7..4c049ab8 100644 --- a/src/Rules/ValidCreditCard.php +++ b/src/Rules/ValidCreditCard.php @@ -8,12 +8,8 @@ class ValidCreditCard implements Rule { /** * Check if the credit card number is valid using the Luhn algorithm. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { $value = preg_replace('/\D/', '', $value); @@ -37,10 +33,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.credit-card'); } diff --git a/src/Rules/ValidDiscordUsername.php b/src/Rules/ValidDiscordUsername.php index d72cce7c..0c03778d 100644 --- a/src/Rules/ValidDiscordUsername.php +++ b/src/Rules/ValidDiscordUsername.php @@ -8,22 +8,16 @@ class ValidDiscordUsername implements Rule { /** * Check discord username is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^.{3,32}#[0-9]{4}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.discord-username'); } diff --git a/src/Rules/ValidDomain.php b/src/Rules/ValidDomain.php index ad2db125..504f1086 100644 --- a/src/Rules/ValidDomain.php +++ b/src/Rules/ValidDomain.php @@ -8,22 +8,16 @@ class ValidDomain implements Rule { /** * Check domain name is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.domain'); } diff --git a/src/Rules/ValidDuplicate.php b/src/Rules/ValidDuplicate.php index d4198c9c..dcddbb22 100644 --- a/src/Rules/ValidDuplicate.php +++ b/src/Rules/ValidDuplicate.php @@ -8,12 +8,8 @@ class ValidDuplicate implements Rule { /** * Check duplicate value. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { $value = str_split($value); @@ -22,10 +18,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.duplicate'); } diff --git a/src/Rules/ValidDuplicateCharacter.php b/src/Rules/ValidDuplicateCharacter.php index 97572772..db934465 100644 --- a/src/Rules/ValidDuplicateCharacter.php +++ b/src/Rules/ValidDuplicateCharacter.php @@ -8,12 +8,8 @@ class ValidDuplicateCharacter implements Rule { /** * Check duplicate characters, splitted by comma. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { $value = explode(',', $value); @@ -22,10 +18,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.duplicate_character'); } diff --git a/src/Rules/ValidEvenNumber.php b/src/Rules/ValidEvenNumber.php index 18f3258f..a8278e00 100644 --- a/src/Rules/ValidEvenNumber.php +++ b/src/Rules/ValidEvenNumber.php @@ -8,22 +8,16 @@ class ValidEvenNumber implements Rule { /** * Check number is even. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^\d*[02468]$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.even-number'); } diff --git a/src/Rules/ValidHashtag.php b/src/Rules/ValidHashtag.php index 48d3a642..20180415 100644 --- a/src/Rules/ValidHashtag.php +++ b/src/Rules/ValidHashtag.php @@ -8,22 +8,16 @@ class ValidHashtag implements Rule { /** * Check value contains hashtag. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^#[^ !@#$%^&*(),.?":{}|<>]*$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.hashtag'); } diff --git a/src/Rules/ValidHexColor.php b/src/Rules/ValidHexColor.php index 43676156..69043cf2 100644 --- a/src/Rules/ValidHexColor.php +++ b/src/Rules/ValidHexColor.php @@ -8,22 +8,16 @@ class ValidHexColor implements Rule { /** * Check hex color is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^#?(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.hex-color'); } diff --git a/src/Rules/ValidHtmlTag.php b/src/Rules/ValidHtmlTag.php index 8d24933d..41bdac7b 100644 --- a/src/Rules/ValidHtmlTag.php +++ b/src/Rules/ValidHtmlTag.php @@ -8,22 +8,16 @@ class ValidHtmlTag implements Rule { /** * Check html tag is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^<([a-z1-6]+)([^<]+)*(?:>(.*)<\/\1>| *\/>)$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.html-tag'); } diff --git a/src/Rules/ValidIban.php b/src/Rules/ValidIban.php index ce2d59ac..e51f9781 100644 --- a/src/Rules/ValidIban.php +++ b/src/Rules/ValidIban.php @@ -15,7 +15,7 @@ class ValidIban implements Rule * * @var array|int[] */ - private array $characterMap = [ + protected array $characterMap = [ 'A' => 10, 'B' => 11, 'C' => 12, @@ -171,23 +171,19 @@ public function __construct(array|string $countries = []) } /** - * Check IBAN. + * Check IBAN is valid. * - * @param string $attribute - * @param mixed $value - * @return bool + * @see https://en.wikipedia.org/wiki/International_Bank_Account_Number */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return $this->isIbanValid($value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.iban'); } diff --git a/src/Rules/ValidImei.php b/src/Rules/ValidImei.php index 3151a52c..79e7b6fa 100644 --- a/src/Rules/ValidImei.php +++ b/src/Rules/ValidImei.php @@ -8,12 +8,8 @@ class ValidImei implements Rule { /** * Check IMEI is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { $imei = $value; @@ -40,10 +36,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.imei'); } diff --git a/src/Rules/ValidIpAddressIPV4.php b/src/Rules/ValidIpAddressIPV4.php index 7b8e70ce..03c9e71a 100644 --- a/src/Rules/ValidIpAddressIPV4.php +++ b/src/Rules/ValidIpAddressIPV4.php @@ -8,22 +8,16 @@ class ValidIpAddressIPV4 implements Rule { /** * Check ip address (ipv4) is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/(?:\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.ipv4'); } diff --git a/src/Rules/ValidIpAddressIPV6.php b/src/Rules/ValidIpAddressIPV6.php index d9486ac6..e2c877d9 100644 --- a/src/Rules/ValidIpAddressIPV6.php +++ b/src/Rules/ValidIpAddressIPV6.php @@ -8,22 +8,16 @@ class ValidIpAddressIPV6 implements Rule { /** * Check ip address (ipv6) is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { - return preg_match('/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/', $value); + return preg_match('/(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.ipv6'); } diff --git a/src/Rules/ValidIranPostalCode.php b/src/Rules/ValidIranPostalCode.php index 5b244138..8be71539 100644 --- a/src/Rules/ValidIranPostalCode.php +++ b/src/Rules/ValidIranPostalCode.php @@ -8,22 +8,16 @@ class ValidIranPostalCode implements Rule { /** * Check postal code is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.postal-code'); } diff --git a/src/Rules/ValidJalaliDate.php b/src/Rules/ValidJalaliDate.php index 550cde7e..5f3642c7 100644 --- a/src/Rules/ValidJalaliDate.php +++ b/src/Rules/ValidJalaliDate.php @@ -8,16 +8,13 @@ class ValidJalaliDate implements Rule { public function __construct( public string $character = '/', - ) {} + ) { + } /** * Check jalali date is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { if (! is_string($value)) { return false; @@ -34,10 +31,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.jalali_date'); } diff --git a/src/Rules/ValidJwt.php b/src/Rules/ValidJwt.php index 1f8ce680..a7cf19b3 100644 --- a/src/Rules/ValidJwt.php +++ b/src/Rules/ValidJwt.php @@ -8,22 +8,16 @@ class ValidJwt implements Rule { /** * Check jwt is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.jwt'); } diff --git a/src/Rules/ValidKebabCase.php b/src/Rules/ValidKebabCase.php index 2d006d55..5cf3e097 100644 --- a/src/Rules/ValidKebabCase.php +++ b/src/Rules/ValidKebabCase.php @@ -8,22 +8,16 @@ class ValidKebabCase implements Rule { /** * Check value is kebab case. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?:\p{Ll}+\-)*\p{Ll}+$/u', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.kebab-case'); } diff --git a/src/Rules/ValidNameDaysWeek.php b/src/Rules/ValidNameDaysWeek.php index bf9d36c4..9d29d109 100644 --- a/src/Rules/ValidNameDaysWeek.php +++ b/src/Rules/ValidNameDaysWeek.php @@ -8,22 +8,16 @@ class ValidNameDaysWeek implements Rule { /** * Check day is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?:sun(?:day)?|mon(?:day)?|tue(?:sday)?|wed(?:nesday)?|thu(?:rsday)?|fri(?:day)?|sat(?:urday)?)$/i', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.name-days-week'); } diff --git a/src/Rules/ValidNationalCard.php b/src/Rules/ValidNationalCard.php index 5f633d87..80305504 100644 --- a/src/Rules/ValidNationalCard.php +++ b/src/Rules/ValidNationalCard.php @@ -8,12 +8,8 @@ class ValidNationalCard implements Rule { /** * Check national card is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { if (! preg_match('/^\d{10}$/', $value)) { return false; @@ -37,10 +33,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.national-card'); } diff --git a/src/Rules/ValidOddNumber.php b/src/Rules/ValidOddNumber.php index fbac8603..48e0a283 100644 --- a/src/Rules/ValidOddNumber.php +++ b/src/Rules/ValidOddNumber.php @@ -8,22 +8,16 @@ class ValidOddNumber implements Rule { /** * Check number is odd. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^\d*[13579]$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.odd-number'); } diff --git a/src/Rules/ValidPascalCase.php b/src/Rules/ValidPascalCase.php index 20acf6f2..0a8dce4e 100644 --- a/src/Rules/ValidPascalCase.php +++ b/src/Rules/ValidPascalCase.php @@ -7,23 +7,17 @@ class ValidPascalCase implements Rule { /** - * Check pascal-case. - * - * @param string $attribute - * @param mixed $value - * @return bool + * Check pascal-case is valid. */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.pascal-case'); } diff --git a/src/Rules/ValidPattern.php b/src/Rules/ValidPattern.php index 09362349..a40ec89e 100644 --- a/src/Rules/ValidPattern.php +++ b/src/Rules/ValidPattern.php @@ -8,20 +8,16 @@ class ValidPattern implements Rule { public function __construct( private int $length, - private string $seperator = '-' + private string $separator = '-' ) { } /** - * Check texts with specific pattern. - * - * @param string $attribute - * @param mixed $value - * @return bool + * Check text with specific pattern. */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { - $texts = explode($this->seperator, $value); + $texts = explode($this->separator, $value); foreach ($texts as $text) { if (strlen($text) !== $this->length) { @@ -34,10 +30,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.pattern'); } diff --git a/src/Rules/ValidPhoneNumber.php b/src/Rules/ValidPhoneNumber.php index 59742973..5732ec92 100644 --- a/src/Rules/ValidPhoneNumber.php +++ b/src/Rules/ValidPhoneNumber.php @@ -13,12 +13,8 @@ public function __construct(protected ?string $code = null) /** * Check phone number is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { if (is_string($this->code)) { $passes = (new CountryPhoneCallback($value, $this->code))->callPhoneValidator(); @@ -26,15 +22,13 @@ public function passes($attribute, $value) return collect($passes)->some(fn ($passe) => $passe); } - return preg_match('/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/', $value); + return preg_match('/^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.phone-number'); } diff --git a/src/Rules/ValidPort.php b/src/Rules/ValidPort.php index a5279ec9..7040f158 100644 --- a/src/Rules/ValidPort.php +++ b/src/Rules/ValidPort.php @@ -8,22 +8,16 @@ class ValidPort implements Rule { /** * Check port is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.port'); } diff --git a/src/Rules/ValidSlashEndOfString.php b/src/Rules/ValidSlashEndOfString.php index 1df0369e..1dfb82d1 100644 --- a/src/Rules/ValidSlashEndOfString.php +++ b/src/Rules/ValidSlashEndOfString.php @@ -8,22 +8,16 @@ class ValidSlashEndOfString implements Rule { /** * Check write slash at the end of string. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/\/+$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.slash-end-of-string'); } diff --git a/src/Rules/ValidSlug.php b/src/Rules/ValidSlug.php index 9645cf0b..9fe3bc8f 100644 --- a/src/Rules/ValidSlug.php +++ b/src/Rules/ValidSlug.php @@ -8,22 +8,16 @@ class ValidSlug implements Rule { /** * Check slug is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.slug'); } diff --git a/src/Rules/ValidSnakeCase.php b/src/Rules/ValidSnakeCase.php index e82e0d60..b08571c8 100644 --- a/src/Rules/ValidSnakeCase.php +++ b/src/Rules/ValidSnakeCase.php @@ -8,22 +8,16 @@ class ValidSnakeCase implements Rule { /** * Check value is snake case. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?:\p{Ll}+_)*\p{Ll}+$/u', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.snake-case'); } diff --git a/src/Rules/ValidStrongPassword.php b/src/Rules/ValidStrongPassword.php index 4fda294e..d23bb1ec 100644 --- a/src/Rules/ValidStrongPassword.php +++ b/src/Rules/ValidStrongPassword.php @@ -8,22 +8,16 @@ class ValidStrongPassword implements Rule { /** * Check password started by capital letters & contains lowercase letters & contains number. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$ %^&*-]).{6,}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.strong-password'); } diff --git a/src/Rules/ValidUlid.php b/src/Rules/ValidUlid.php index 620d51d1..ed801fd9 100644 --- a/src/Rules/ValidUlid.php +++ b/src/Rules/ValidUlid.php @@ -7,23 +7,17 @@ class ValidUlid implements Rule { /** - * Check ulid. - * - * @param string $attribute - * @param mixed $value - * @return bool + * Check ulid is valid. */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/[0-7][0-9A-HJKMNP-TV-Z]{25}/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.ulid'); } diff --git a/src/Rules/ValidUrl.php b/src/Rules/ValidUrl.php index 9738b758..1d3acdee 100644 --- a/src/Rules/ValidUrl.php +++ b/src/Rules/ValidUrl.php @@ -8,22 +8,16 @@ class ValidUrl implements Rule { /** * Check url is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.url'); } diff --git a/src/Rules/ValidUsername.php b/src/Rules/ValidUsername.php index 9e1c8b40..35c3dfbe 100644 --- a/src/Rules/ValidUsername.php +++ b/src/Rules/ValidUsername.php @@ -8,22 +8,16 @@ class ValidUsername implements Rule { /** * It checks that the length of the username must be between 3 and 15 characters without spaces. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^[a-z0-9_-]{3,15}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.username'); } diff --git a/src/Rules/ValidUuid.php b/src/Rules/ValidUuid.php index 2501d85c..022ddba7 100644 --- a/src/Rules/ValidUuid.php +++ b/src/Rules/ValidUuid.php @@ -8,22 +8,16 @@ class ValidUuid implements Rule { /** * Check uuid is valid. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return preg_match('/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/', $value); } /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.uuid'); } diff --git a/src/Rules/ValidVatId.php b/src/Rules/ValidVatId.php index 19405bb5..e6e23f52 100644 --- a/src/Rules/ValidVatId.php +++ b/src/Rules/ValidVatId.php @@ -8,12 +8,8 @@ class ValidVatId implements Rule { /** * Check VAT ID for validity. - * - * @param string $attribute - * @param mixed $value - * @return bool */ - public function passes($attribute, $value) + public function passes($attribute, $value): bool { // Remove all characters except letters and numbers $value = preg_replace('/[^a-zA-Z0-9]/', '', $value); @@ -23,10 +19,8 @@ public function passes($attribute, $value) /** * Get the validation error message. - * - * @return string */ - public function message() + public function message(): string { return __('validate.vat-id'); } diff --git a/src/Traits/IbanTrait.php b/src/Traits/IbanTrait.php index 0bec9bb4..f3f00f69 100644 --- a/src/Traits/IbanTrait.php +++ b/src/Traits/IbanTrait.php @@ -6,10 +6,8 @@ trait IbanTrait { /** * Set value of $countries property. - * - * @return void */ - private function setCountries(?array $countries) + private function setCountries(?array $countries): void { if (empty($countries)) { $this->countries = []; @@ -28,10 +26,8 @@ private function setCountries(?array $countries) /** * Check IBAN is valid. - * - * @return bool */ - private function isIbanValid(string $iban) + private function isIbanValid(string $iban): bool { if (! $this->checkIbanFormat($iban)) { return false; @@ -52,10 +48,8 @@ private function isIbanValid(string $iban) /** * Check IBAN format is valid. - * - * @return bool */ - private function checkIbanFormat(string $iban) + private function checkIbanFormat(string $iban): bool { if (empty($iban)) { return false; @@ -71,40 +65,32 @@ private function checkIbanFormat(string $iban) /** * Get IBAN country code. - * - * @return string */ - private function getIbanCountryCode(string $iban) + private function getIbanCountryCode(string $iban): string { return substr($iban, 0, 2); } /** * Check if bcmod function is available. - * - * @return bool */ - private function checkIfBcmodIsAvailable() + private function checkIfBcmodIsAvailable(): bool { return function_exists('bcmod'); } /** * Check two first character's validity. - * - * @return bool */ - private function twoFirstCharactersValid(string $countryCode) + private function twoFirstCharactersValid(string $countryCode): bool { return ! empty($countryCode) && ctype_alpha($countryCode); } /** * Check countries of the IBAN. - * - * @return bool */ - private function isCountriesValid(string $ibanCountryCode) + private function isCountriesValid(string $ibanCountryCode): bool { if (empty($this->countries)) { return true; @@ -121,10 +107,8 @@ private function isCountriesValid(string $ibanCountryCode) /** * Check country of the IBAN. - * - * @return bool */ - private function isCountryValid(string $country, string $ibanCountryCode) + private function isCountryValid(string $country, string $ibanCountryCode): bool { return ! empty($country) && isset($this->ibanLengthByCountry[$country]) @@ -133,10 +117,8 @@ private function isCountryValid(string $country, string $ibanCountryCode) /** * Check country of the IBAN. - * - * @return bool */ - private function isIbanLengthValid(string $iban, string $ibanCountryCode) + private function isIbanLengthValid(string $iban, string $ibanCountryCode): bool { return strlen($iban) === $this->ibanLengthByCountry[$ibanCountryCode]; } diff --git a/src/Utils/CountryPhoneCallback.php b/src/Utils/CountryPhoneCallback.php index b03a9d14..8834e2e1 100644 --- a/src/Utils/CountryPhoneCallback.php +++ b/src/Utils/CountryPhoneCallback.php @@ -6,9 +6,6 @@ class CountryPhoneCallback { /** * Create a new phone validator instance. - * - * @param mixed $value The phone number to validate. - * @param string $code The country codes to validate against. String can be separated by comma */ public function __construct(private mixed $value, private string $code, ?string $attribute = null) { @@ -18,170 +15,136 @@ public function __construct(private mixed $value, private string $code, ?string /** * Validate Iran phone number. - * - * @return false|int */ - protected function validateIR() + protected function validateIR(): false|int { return preg_match('/^(\+98|0)?9\d{9}$/', $this->value); } /** * Validate Iran phone number. - * - * @return false|int */ - protected function validateEN() + protected function validateEN(): false|int { return preg_match('/^(?:\+44|0)7\d{9}$/', $this->value); } /** * Validate Nigeria phone number. - * - * @return false|int */ - protected function validateNE() + protected function validateNE(): false|int { return preg_match('/^(\+227|00227|227)?\d{8}$/', $this->value); } /** * Validate Saudi Arabia phone number. - * - * @return false|int */ - protected function validateSA() + protected function validateSA(): false|int { return preg_match('/^((\+966)|0)?5\d{8}$/', $this->value); } /** * Validate Germany phone number. - * - * @return false|int */ - protected function validateDE() + protected function validateDE(): false|int { return preg_match('/^((\+49)|(0))(1|15|16|17|19|30|31|32|33|34|40|41|42|43|44|49|151|152|153|155|156|157|159|160|162|163|180|181|182|183|184|185|186|187|188|170|171|172|173|174|175|176|177|178|179)\d{7,8}$/', $this->value); } /** * Validate Greece phone number. - * - * @return false|int */ - protected function validateGR() + protected function validateGR(): false|int { return preg_match('/^\+30[2-9]\d{2}\d{3}\d{4}$/', $this->value); } /** * Validate Spain phone number. - * - * @return false|int */ - protected function validateES() + protected function validateES(): false|int { return preg_match('/^(?:\+34|0034|34)?[6789]\d{8}$/', $this->value); } /** * Validate France phone number. - * - * @return false|int */ - protected function validateFR() + protected function validateFR(): false|int { - return preg_match('/^(?:\+33|0033|0)(?:(?:[1-9](?:\d{2}){4})|(?:[67]\d{8}))$/', $this->value); + return preg_match('/^(?:\+33|0033|0)(?:[1-9](?:\d{2}){4}|[67]\d{8})$/', $this->value); } /** * Validate India phone number. - * - * @return false|int */ - protected function validateIN() + protected function validateIN(): false|int { return preg_match('/^(?:(?:\+|0{0,2})91(\s|-)?)?[6789]\d{9}$/', $this->value); } /** * Validate Indonesia phone number. - * - * @return false|int */ - protected function validateID() + protected function validateID(): false|int { return preg_match('/^(?:\+62|0)(?:\d{2,3}\s?){1,2}\d{4,8}$/', $this->value); } /** * Validate Italy phone number. - * - * @return false|int */ - protected function validateIT() + protected function validateIT(): false|int { return preg_match('/^\+39\d{8,10}$/', $this->value); } /** * Validate Japanese phone number. - * - * @return false|int */ - protected function validateJA() + protected function validateJA(): false|int { return preg_match('/(\d{2,3})-?(\d{3,4})-?(\d{4})/', $this->value); } /** * Validate Korean phone number. - * - * @return false|int */ - protected function validateKO() + protected function validateKO(): false|int { return preg_match('/^(?:\+82|0)(?:10|1[1-9])-?\d{3,4}-?\d{4}$/', $this->value); } /** * Validate Russian phone number. - * - * @return false|int */ - protected function validateRU() + protected function validateRU(): false|int { return preg_match('/^(?:\+7|8)(?:\s?\(?\d{3}\)?\s?\d{3}(?:-?\d{2}){2}|\s?\d{2}(?:\s?\d{2}){3})$/', $this->value); } /** * Validate Sweden phone number. - * - * @return false|int */ - protected function validateSE() + protected function validateSE(): false|int { return preg_match('/^(?:\+46|0) ?(?:[1-9]\d{1,2}-?\d{2}(?:\s?\d{2}){2}|7\d{2}-?\d{2}(?:\s?\d{2}){2})$/', $this->value); } /** * Validate Turkey phone number. - * - * @return false|int */ - protected function validateTR() + protected function validateTR(): false|int { return preg_match('/^(?:\+90|0)(?:\s?[1-9]\d{2}\s?\d{3}\s?\d{2}\s?\d{2}|[1-9]\d{2}-?\d{3}-?\d{2}-?\d{2})$/', $this->value); } /** * Validate Chinese phone number. - * - * @return false|int */ - protected function validateZH() + protected function validateZH(): false|int { return preg_match('/^(?:\+86)?1[3-9]\d{9}$/', $this->value); } @@ -189,8 +152,6 @@ protected function validateZH() /** * Call the phone validator method for each country code and return the results. * - * @return array An array of validation results, where each key is a country code and the value is either `true` or `false`. - * * @throws \BadMethodCallException if the validator method for a country code does not exist. */ public function callPhoneValidator(): array