generateRandomString(Code::LENGTH) ); } while ($this->exists($code)); return $code; } private function generateRandomString(int $length): string { $dictionary = implode( '', array_unique(str_split(Code::ALLOWED_CHARACTERS)) ); $dictionaryLength = strlen($dictionary); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $dictionary[random_int(0, $dictionaryLength - 1)]; } return $randomString; } private function exists(Code $code): bool { return $this->codeDirectory->exists($code); } }