Skip to content

Commit

Permalink
Update Base62.php (#6177)
Browse files Browse the repository at this point in the history
  • Loading branch information
assert6 committed Sep 30, 2023
1 parent 7eb45c2 commit dfe4ff8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Base62.php
Expand Up @@ -21,19 +21,19 @@ public static function encode(int $number): string
{
$chars = [];
while ($number > 0) {
$remain = $number % self::BASE;
$chars[] = self::CHARS[$remain];
$number = ($number - $remain) / self::BASE;
$remain = $number % static::BASE;
$chars[] = static::CHARS[$remain];
$number = ($number - $remain) / static::BASE;
}
return implode('', array_reverse($chars));
}

public static function decode(string $data): int
{
return array_reduce(array_map(function ($character) {
return strpos(self::CHARS, $character);
return strpos(static::CHARS, $character);
}, str_split($data)), function ($result, $remain) {
return $result * self::BASE + $remain;
return $result * static::BASE + $remain;
});
}
}

0 comments on commit dfe4ff8

Please sign in to comment.