Skip to content

Commit

Permalink
Validate birthday in austrian insurance number (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrempler authored Jun 5, 2024
1 parent 7a0b80b commit 09c9ba2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Rules/AustrianInsuranceNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function isValid(mixed $value): bool
return is_numeric($value)
&& $this->startsNotWithZero($value)
&& $this->hasValidLength($value)
&& $this->hasValidBirthday($value)
&& $this->checkChecksum($value);
}

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

private function hasValidBirthday(string $svnumber): bool
{
$splittedBirthday = str_split(substr($svnumber, 4), 2);

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'],
];
}
}

0 comments on commit 09c9ba2

Please sign in to comment.