diff --git a/actions-web.php b/actions-web.php index 0dd8e60..fb4ae50 100644 --- a/actions-web.php +++ b/actions-web.php @@ -682,14 +682,14 @@ function getcouponlist() function generatecoupons($multiplier) { - global $db, $credit; + global $db, $credit, $codeGenerator; if (iscreditenabled() == false) { return; } // if credit system disabled, exit $requiredcredit = $credit['min'] + $credit['rent'] + $credit['longrental']; $value = $requiredcredit * $multiplier; - $codes = generatecodes(10, 6); + $codes = $codeGenerator->generate(10, 6); foreach ($codes as $code) { $result = $db->query("INSERT IGNORE INTO coupons SET coupon='" . $code . "',value='" . $value . "',status='0'"); } diff --git a/common.php b/common.php index f96fa0d..782a099 100644 --- a/common.php +++ b/common.php @@ -1,5 +1,7 @@ acceptableChars), 0, $length); + } + + return array_slice($codes, 0, ($count)); + } +} diff --git a/src/Credit/CodeGenerator/CodeGeneratorInterface.php b/src/Credit/CodeGenerator/CodeGeneratorInterface.php new file mode 100644 index 0000000..cd2cf13 --- /dev/null +++ b/src/Credit/CodeGenerator/CodeGeneratorInterface.php @@ -0,0 +1,8 @@ +generate($count, $length, $wastage); + $this->assertCount($count, $codes); + foreach ($codes as $code) { + $this->assertEquals($length, strlen($code)); + $this->assertRegExp('/^[' . $this->acceptableChars . ']{' . $length . '}$/', $code); + } + } +}