Skip to content

Commit

Permalink
Update public id format (#11391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg authored Jan 31, 2025
1 parent b82c7b7 commit dec5eba
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/Adherent/PublicIdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,15 @@ public function generate(): string

public static function build(): string
{
$characters = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';

$charactersArray = str_split($characters);

shuffle($charactersArray);

$block1 = self::generateRandomBlock($charactersArray, 3);
$block2 = self::generateRandomBlock($charactersArray, 3);

return $block1.'-'.$block2;
return self::generateRandomBlock(3).'-'.self::generateRandomBlock(3);
}

private static function generateRandomBlock(array $characters, int $length): string
private static function generateRandomBlock(int $length): string
{
$block = '';
$maxIndex = \count($characters) - 1;

for ($i = 0; $i < $length; ++$i) {
$block .= $characters[random_int(0, $maxIndex)];
$block .= random_int(0, 9);
}

return $block;
Expand Down

0 comments on commit dec5eba

Please sign in to comment.