1 | <?php |
||
5 | final class Modulo11 |
||
6 | { |
||
7 | /** |
||
8 | * Number of digits to be calculated. |
||
9 | * @var int |
||
10 | */ |
||
11 | protected $digitsCount; |
||
12 | |||
13 | /** |
||
14 | * Max size of factor. |
||
15 | * @var int |
||
16 | */ |
||
17 | protected $maxMultiplier; |
||
18 | |||
19 | /** |
||
20 | * When calculated digit is equals 10 it will be converted to X. |
||
21 | * @var bool |
||
22 | */ |
||
23 | private $convertX; |
||
24 | |||
25 | /** |
||
26 | * Modulo11 constructor. |
||
27 | * |
||
28 | * @param int $numberOfDigits Number of digits to be calculated. |
||
29 | * @param int $multiplierLimit Max size of factor. |
||
30 | * @param bool $convertX When calculated digit is equals 10 it will be converted to X. |
||
31 | */ |
||
32 | 12 | public function __construct($numberOfDigits, $multiplierLimit, $convertX = true) |
|
40 | |||
41 | /** |
||
42 | * Generic validation for many type of numbers. |
||
43 | * |
||
44 | * @param string $number A number to be validate. |
||
45 | * |
||
46 | * @return boolean |
||
47 | */ |
||
48 | 12 | public function validate($number) |
|
56 | |||
57 | /** |
||
58 | * Calculates digits from base numbers (without last N digits). |
||
59 | * |
||
60 | * @param string $number Base number to be calculated. |
||
61 | * |
||
62 | * @return string Returns N calculated digits. |
||
63 | */ |
||
64 | 12 | private function calculateDigits($number) |
|
73 | |||
74 | /** |
||
75 | * Calculates digit from base number (without last digit). |
||
76 | * |
||
77 | * @param string $number Base number to be calculated. |
||
78 | * |
||
79 | * @return string Returns a calculated digit. |
||
80 | */ |
||
81 | 12 | private function calculateDigit($number) |
|
95 | |||
96 | /** |
||
97 | * Apply factor in each base number and calculates the sum of their. |
||
98 | * |
||
99 | * @param string $baseNumber Base number (number without N digits) |
||
100 | * |
||
101 | * @return int Returns the sum of base numbers with factors applied. |
||
102 | */ |
||
103 | 12 | protected function calculate($baseNumber) |
|
118 | } |