| Total Complexity | 2 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 6 | ||
| 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 | * @param array $attributes |
||
| 20 | * |
||
| 21 | * @return Collection |
||
| 22 | */ |
||
| 23 | 1 | public function generateCoupons(int $times = 5, int $length = 7, array $attributes = []): Collection |
|
| 24 | { |
||
| 25 | 1 | return Collection::times($times, function () use ($length, $attributes) { |
|
| 26 | 1 | $fields = collect([ |
|
|
|
|||
| 27 | 1 | $this->model->getCodeColumn() => Str::random($length), |
|
| 28 | 1 | $this->model->getTypeColumn() => CouponContract::TYPE_PERCENTAGE, |
|
| 29 | 1 | ]); |
|
| 30 | |||
| 31 | 1 | $this->model->create($fields->merge($attributes)->toArray()); |
|
| 32 | 1 | }); |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Generate the coupon code to redeem only by the specified model. |
||
| 37 | * |
||
| 38 | * @param Model $redeemer |
||
| 39 | * @param string $code |
||
| 40 | * @param array $attributes |
||
| 41 | * |
||
| 42 | * @return CouponContract |
||
| 43 | */ |
||
| 44 | 1 | public function generateCouponFor(Model $redeemer, string $code, array $attributes = []): CouponContract |
|
| 54 | } |
||
| 55 | } |
||
| 56 |