99namespace Magento \SalesRule \Model \Quote ;
1010
1111use Magento \SalesRule \Model \Coupon \Massgenerator ;
12- use Magento \SalesRule \Helper \Coupon ;
1312
1413/**
1514 * Validate the coupon code length and quantity.
1615 */
17- class ValidateCouponLengthWithQuantity implements ValidateCouponLengthWithQuantityInterface
16+ class ValidateCouponLengthWithQuantity extends Massgenerator implements ValidateCouponLengthWithQuantityInterface
1817{
19- /**
20- * Initialize Sales rule coupon property
21- *
22- * @var Coupon
23- */
24- protected Coupon $ salesRuleCoupon ;
25-
26- /**
27- * Generate constructor.
28- *
29- * @param Coupon $salesRuleCoupon
30- */
31- public function __construct (
32- Coupon $ salesRuleCoupon
33- ) {
34- $ this ->salesRuleCoupon = $ salesRuleCoupon ;
35- }
36-
3718 /**
3819 * Validate coupon code length with quantity
3920 *
@@ -42,20 +23,8 @@ public function __construct(
4223 */
4324 public function validateCouponCodeLengthWithQuantity (array $ couponCodeDataArray ): int
4425 {
45- $ maxProbability = Massgenerator::MAX_PROBABILITY_OF_GUESSING ;
46- $ chars = count ($ this ->salesRuleCoupon ->getCharset ($ couponCodeDataArray ['format ' ]));
47- $ size = $ couponCodeDataArray ['qty ' ];
48- $ length = (int )$ couponCodeDataArray ['length ' ];
49- $ maxCodes = pow ($ chars , $ length );
50- $ probability = $ size / $ maxCodes ;
51-
52- if ($ probability > $ maxProbability ) {
53- do {
54- $ length ++;
55- $ maxCodes = pow ($ chars , $ length );
56- $ probability = $ size / $ maxCodes ;
57- } while ($ probability > $ maxProbability );
58- }
59- return $ length ;
26+ $ this ->setData ($ couponCodeDataArray );
27+ $ this ->increaseLength ();
28+ return $ this ->getLength ();
6029 }
6130}
0 commit comments