Skip to content

Commit

Permalink
AustrianInsuranceNumber birthday validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrempler committed Jun 2, 2024
1 parent fd643d6 commit d0a589c
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 @@ -38,6 +38,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 @@ -51,6 +52,25 @@ private function startsNotWithZero(string $svnumber): bool
return (int) $svnumber[0] !== 0;
}

private function hasValidBirthday($svnumber): bool

Check failure on line 55 in src/Rules/AustrianInsuranceNumber.php

View workflow job for this annotation

GitHub Actions / Testing on PHP 8.3

Method Intervention\Validation\Rules\AustrianInsuranceNumber::hasValidBirthday() has parameter $svnumber with no type specified.
{
$splittedBirthday = str_split(substr($svnumber, 4, 10), 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 d0a589c

Please sign in to comment.