Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate birthday in austrian insurance number #85

Merged
merged 9 commits into from
Jun 5, 2024
20 changes: 20 additions & 0 deletions src/Rules/AustrianInsuranceNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function isValid(mixed $value): bool
return is_numeric($value)
&& $this->startsNotWithZero($value)
&& $this->hasValidLength($value)
&& $this->hasValidBirthday($value)
olivervogel marked this conversation as resolved.
Show resolved Hide resolved
&& $this->checkChecksum($value);
}

Expand All @@ -51,6 +52,25 @@ private function startsNotWithZero(string $svnumber): bool
return (int) $svnumber[0] !== 0;
}

private function hasValidBirthday(string $svnumber): bool
{
$splittedBirthday = str_split(substr($svnumber, 4, 10), 2);
lkrempler marked this conversation as resolved.
Show resolved Hide resolved

if (!in_array((int) $splittedBirthday[0], range(1, 31), true)) {
return false;
}

if (!in_array((int) $splittedBirthday[1], range(1, 20), true)) {
return false;
}

if (!in_array((int) $splittedBirthday[2], range(0, 99), true)) {
return false;
}

return true;
}

private function checkChecksum(string $svnumber): bool
{
if (strlen($svnumber) !== $this->length) {
Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/AustrianInsuranceNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static function dataProvider(): array
[false, '8753080475'],
[false, 'foo'],
[true, '1230 011471'],
[false, '9999999999'],
[false, '9999202501'],
[false, '9999009901'],
[true, '1680250250'],
];
}
}
Loading