0) { $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 { if ($data === '' || strlen($data) !== strspn($data, self::CHARS)) { throw new InvalidArgumentException('The decode data contains content outside of CHARS.'); } return array_reduce(array_map(function ($character) { return strpos(static::CHARS, $character); }, str_split($data)), function ($result, $remain) { return $result * static::BASE + $remain; }); } }