| Total Complexity | 2 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | trait GeneratesCoupons |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Generate the coupon codes. |
||
| 16 | * |
||
| 17 | * @param int $times |
||
| 18 | * @param int $length |
||
| 19 | * |
||
| 20 | * @return Collection |
||
| 21 | */ |
||
| 22 | 1 | public function generateCoupons(int $times = 5, int $length = 7): Collection |
|
| 23 | { |
||
| 24 | 1 | return Collection::times($times, fn () => $this->model->create([ |
|
| 25 | 1 | $this->model->getCodeColumn() => Str::random($length), |
|
| 26 | ])); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Generate the coupon code to redeem only by the specified model. |
||
| 31 | * |
||
| 32 | * @param Model $redeemer |
||
| 33 | * @param string $code |
||
| 34 | * @param array $attributes |
||
| 35 | * |
||
| 36 | * @return CouponContract |
||
| 37 | */ |
||
| 38 | 1 | public function generateCouponFor(Model $redeemer, string $code, array $attributes = []): CouponContract |
|
| 47 | } |
||
| 48 | } |
||
| 49 |