Closed edgarsn closed 1 year ago
About failing psalm check - I don't have a experience using psalm, but seems that changing foreach loop to this fixes the check.
foreach ($partialNumberSplit as $key => $digit) {
if (!isset($idDigitValidator[$key])) {
continue;
}
$total += $idDigitValidator[$key] * (int) $digit;
}
... but is that the best way how to deal with it?
About failing psalm check - I don't have a experience using psalm, but seems that changing foreach loop to this fixes the check.
foreach ($partialNumberSplit as $key => $digit) { if (!isset($idDigitValidator[$key])) { continue; } $total += $idDigitValidator[$key] * (int) $digit; }
... but is that the best way how to deal with it?
Skip the continue and make the if the other way around only execute if exists. Originally its a possible nullpointer exception so
What is the reason for this PR?
Generated latvian personal identity number (PIN) part after dash is invalid. By implementing this, developers will have ability to work with randomly generated, valid PIN, especially if somewhere in tests they rely on a valid PIN.
Author's checklist
Summary of changes
https://en.wikipedia.org/wiki/National_identification_number#Latvia
Shortly:
0
, 20c. =1
, 21c. =2
). This was random number.000 - 999
. May stay random.In this PR all theese things are taken into account, making PIN totally valid.
About checksum digit formula
Format:
ABCDEF-XGHIZ
Formula:(1101-(1*A+6*B+3*C+7*D+9*E+10*F+5*X+8*G+4*H+2*I)) | Mod 11 | Mod 10
Example: Birth date:
1981-05-24
Century:1
Serial number (random):579
PIN without checksum (X) yet:240581-1579X
Inserting real numbers into formula:
Which makes PIN to be:
240581-15799
Review checklist