From 1b73105180aa69b7826fb037dc1df8387e30d640 Mon Sep 17 00:00:00 2001 From: Lukas Krempler Date: Thu, 30 May 2024 15:37:09 +0200 Subject: [PATCH] Updated Austrian insurance number and readme (#84) * Added validation rule for austrian insurance numbers to readme * Fixed typo in translation * Type casting, translations and readme --- README.md | 6 ++++++ src/Rules/AustrianInsuranceNumber.php | 4 ++-- src/lang/es/validation.php | 1 + src/lang/fr/validation.php | 1 + src/lang/nl/validation.php | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7773a20..f7243a4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ Or add your custom messages directly to the validator like [described in the doc The following validation rules are available with this package. +### Austrian insurance Number (austrian social security number) + +The field under validation must be an [Austrian insurance number](https://de.wikipedia.org/wiki/Sozialversicherungsnummer#%C3%96sterreich) + + public Intervention\Validation\Rules\AustrianInsuranceNumber::__construct() + ### Base64 encoded string The field under validation must be [Base64 encoded](https://en.wikipedia.org/wiki/Base64). diff --git a/src/Rules/AustrianInsuranceNumber.php b/src/Rules/AustrianInsuranceNumber.php index ee3e866..1f6e912 100644 --- a/src/Rules/AustrianInsuranceNumber.php +++ b/src/Rules/AustrianInsuranceNumber.php @@ -33,7 +33,7 @@ class AustrianInsuranceNumber extends AbstractRule */ public function isValid(mixed $value): bool { - $value = str_replace(' ', '', strval($value)); + $value = str_replace(' ', '', (string) $value); return is_numeric($value) && $this->startsNotWithZero($value) @@ -62,7 +62,7 @@ private function checkChecksum(string $svnumber): bool $sum = 0; for ($c = 0, $cMax = strlen($svnumberWithoutChecksum); $c < $cMax; $c++) { - $result = intval($svnumberWithoutChecksum[$c]) * $this->multiplierSeries[$c]; + $result = (int) $svnumberWithoutChecksum[$c] * $this->multiplierSeries[$c]; $sum += $result; } $checksum = $sum % 11; diff --git a/src/lang/es/validation.php b/src/lang/es/validation.php index 968f6a6..570cfa1 100644 --- a/src/lang/es/validation.php +++ b/src/lang/es/validation.php @@ -33,6 +33,7 @@ 'gtin' => ':attribute no es un número GTIN válido.', 'postalcode' => 'El valor de :attribute debe ser un código postal válido.', 'mimetype' => 'El valor de :attribute no contiene un tipo de media de internet (MIME-Type) válido.', + 'austrianinsurancenumber' => 'El valor de :attribute contiene un número de seguro austriaco válido.', 'grid' => 'El valor de :attribute no contiene un Global Release Identifier (GRid) válido.', 'hslcolor' => ':attribute no es un valor de color HSL válido.', 'hsvcolor' => ':attribute no es un valor de color HSV válido.', diff --git a/src/lang/fr/validation.php b/src/lang/fr/validation.php index 1d2300e..d1a51f6 100644 --- a/src/lang/fr/validation.php +++ b/src/lang/fr/validation.php @@ -40,6 +40,7 @@ 'gtin' => 'Le :attribute doit être un GTIN valide.', 'postalcode' => 'La valeur :attribute doit être un code postal valide.', 'mimetype' => 'La valeur :attribute ne contient pas de type de média Internet valide (type MIME).', + 'austrianinsurancenumber' => 'La valeur :attribute ne contient pas de numéro d\'assurance autrichien valide.', 'grid' => 'Le :attribute doit être un Global Release Identifier (GRid) valide.', 'hslcolor' => ':attribute n\'est pas une valeur de couleur HSL valide', 'hsvcolor' => ':attribute n\'est pas une valeur de couleur HSV valide', diff --git a/src/lang/nl/validation.php b/src/lang/nl/validation.php index c58cd49..d40776a 100644 --- a/src/lang/nl/validation.php +++ b/src/lang/nl/validation.php @@ -33,6 +33,7 @@ 'gtin' => ':attribute is geen geldig Global Trade Item Number (GTIN).', 'postalcode' => ':attribute moet een geldige postcode zijn.', 'mimetype' => ':attribute bevat geen geldig internetmediatype (MIME-type).', + 'austrianinsurancenumber' => 'De waarde :attribute bevat geen geldig Oostenrijks verzekeringsnummer.', 'grid' => ':attribute moet een geldige Global Release Identifier (GRid) zijn.', 'hslcolor' => ':attribute is geen geldige HSL-kleurwaarde', 'hsvcolor' => ':attribute is geen geldige HSV-kleurwaarde',