| Total Complexity | 4 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Coverage | 89.47% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | trait HasCoupons |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Polymorphic relation to the coupons. |
||
| 18 | * |
||
| 19 | * @return MorphToMany |
||
| 20 | */ |
||
| 21 | 11 | public function coupons(): MorphToMany |
|
| 22 | { |
||
| 23 | 11 | return $this->morphToMany(app(CouponContract::class), Str::singular( |
|
|
|
|||
| 24 | 11 | config('couponables.pivot_table', 'couponables') |
|
| 25 | 11 | ))->withPivot( |
|
| 26 | 11 | call(CouponPivotContract::class)->getRedeemedAtColumn() |
|
| 27 | ); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Use the coupon. |
||
| 32 | * |
||
| 33 | * @param string $code |
||
| 34 | * |
||
| 35 | * @return CouponContract |
||
| 36 | */ |
||
| 37 | 13 | public function redeemCoupon(string $code): CouponContract |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @alias redeemCoupon() |
||
| 51 | * |
||
| 52 | * @param string $code |
||
| 53 | * |
||
| 54 | * @return CouponContract |
||
| 55 | */ |
||
| 56 | public function applyCoupon(string $code): CouponContract |
||
| 57 | { |
||
| 58 | return call($this)->redeemCoupon($code); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Check if coupon with this code is already used. |
||
| 63 | * |
||
| 64 | * @param string $code |
||
| 65 | * |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | 2 | public function isCouponAlreadyUsed(string $code): bool |
|
| 76 | } |
||
| 77 | } |
||
| 78 |