hashids = new Hashids($salt, 11); } public function encode(int $id): string { return $this->hashids->encode($id); } /** * @throws InvalidHashException */ public function decode(string $hash): int { $decoded = $this->hashids->decode($hash); if (count($decoded) === 0) { throw new InvalidHashException('Hash not valid'); } return $decoded[0]; } public function isValid(string $hash): bool { return count($this->hashids->decode($hash)) !== 0; } }