Skip to content

Commit a5bed45

Browse files
authored
Merge pull request #2 from freezy-sk/weight
Remove weights const
2 parents 7f16f37 + a646d22 commit a5bed45

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

ICOValidator.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ final class ICOValidator
1717
public const ERROR_NONE = 0;
1818
public const ERROR_FORMAT = 1;
1919
public const ERROR_MODULO = 2;
20-
private const WEIGHTS = [
21-
0 => 8,
22-
1 => 7,
23-
2 => 6,
24-
3 => 5,
25-
4 => 4,
26-
5 => 3,
27-
6 => 2,
28-
];
2920

3021
public function validate(string $value): int
3122
{
@@ -39,8 +30,8 @@ public function validate(string $value): int
3930
$chars = str_split($value);
4031
$sum = 0;
4132

42-
for ($i = 0; $i < 7; $i++) {
43-
$sum += $chars[$i] * self::WEIGHTS[$i];
33+
for ($i = 0, $w = 8; $i < 7; $i++, $w--) {
34+
$sum += $chars[$i] * $w;
4435
}
4536

4637
$modulo = $sum % 11;

0 commit comments

Comments
 (0)