Skip to content

Commit

Permalink
count out before looping
Browse files Browse the repository at this point in the history
  • Loading branch information
zgabievi committed Sep 3, 2017
1 parent b5a43c5 commit 75325a3
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Promocodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,21 @@ private function generate()
$promocode = '';
$random = [];

// take needed length of string from characters and randomize it
for ($i = 1; $i <= $this->length; $i++) {
$character = $characters[rand(0, strlen($characters) - 1)];
$random[] = $character;
}

// shuffle randomized characters
shuffle($random);
$length = count($random);

// set prefix for promocode
$promocode .= $this->getPrefix();

// loop through asterisks and change with random symbol
for ($i = 0; $i < count($random); $i++) {
for ($i = 0; $i < $length; $i++) {
$mask = preg_replace('/\*/', $random[$i], $mask, 1);
}

// set updated mask as code
$promocode .= $mask;

// set suffix for promocode
$promocode .= $this->getSuffix();

return $promocode;
Expand Down

0 comments on commit 75325a3

Please sign in to comment.