Skip to content

Commit

Permalink
Update KeyGeneratorService.php
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Dec 15, 2023
1 parent 10c78c7 commit cc105ed
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/Services/KeyGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function generate(string $value): string
$this->ensureStringCanBeUsedAsKey($key) === false
|| strlen($key) < config('urlhub.hash_length')
) {
$key = $this->generateRandomString(self::ALPHABET, config('urlhub.hash_length'));
$key = $this->generateRandomString();
}

return $key;
Expand All @@ -43,14 +43,12 @@ public function generateSimpleString(string $value): string
* Generate a random string of specified length. The string will only contain
* characters from the specified character set.
*
* @param string $alphabet The alphabet as a sequence of unique characters.
* @param int $length The length of the string to generate.
* @return string The generated random string.
*/
public function generateRandomString(string $alphabet, int $length): string
public function generateRandomString(): string
{
do {
$urlKey = $this->getBytesFromString($alphabet, $length);
$urlKey = $this->getBytesFromString(self::ALPHABET, config('urlhub.hash_length'));
} while ($this->ensureStringCanBeUsedAsKey($urlKey) == false);

return $urlKey;
Expand Down

0 comments on commit cc105ed

Please sign in to comment.