1 | <?php |
||
12 | class Modulo11 |
||
13 | { |
||
14 | /** |
||
15 | * Map modulo 11 remainder to check digit map |
||
16 | */ |
||
17 | private const REMAINDER_TO_CHECK_DIGIT_MAP = [ |
||
18 | 0 => '0', |
||
19 | 1 => '1', |
||
20 | 2 => '2', |
||
21 | 3 => '3', |
||
22 | 4 => '4', |
||
23 | 5 => '5', |
||
24 | 6 => '6', |
||
25 | 7 => '7', |
||
26 | 8 => '8', |
||
27 | 9 => '9', |
||
28 | 10 => 'X', |
||
29 | 11 => '0', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * Calculate the modulo 11 check digit for number |
||
34 | * |
||
35 | * @throws LogicException If $number is not numerical |
||
36 | */ |
||
37 | 134 | public static function calculateCheckDigit(string $number): string |
|
54 | |||
55 | /** |
||
56 | * Calculate weight based on position in number |
||
57 | * |
||
58 | * @param int $pos Position in number (starts from 0) |
||
59 | * @param int $start Start value for weight calculation (value of position 0) |
||
60 | */ |
||
61 | 129 | protected static function getWeight(int $pos, int $start = 1): int |
|
71 | } |
||
72 |