Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.62% |
11 / 13 |
|
71.43% |
5 / 7 |
CRAP | |
0.00% |
0 / 1 |
| InfluencerCoupon | |
84.62% |
11 / 13 |
|
71.43% |
5 / 7 |
7.18 | |
0.00% |
0 / 1 |
| casts | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| normalize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| tenant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| influencer | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| integration | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| orders | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use App\Enums\CouponStatus; |
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
| 9 | use Illuminate\Database\Eloquent\Relations\HasMany; |
| 10 | |
| 11 | class InfluencerCoupon extends Model |
| 12 | { |
| 13 | use HasFactory; |
| 14 | |
| 15 | protected $fillable = [ |
| 16 | 'tenant_id', 'store_id', 'influencer_id', 'store_integration_id', 'coupon_code_original', |
| 17 | 'coupon_code_normalized', 'discount_percentage', 'external_coupon_id', 'status', |
| 18 | 'started_at', 'ended_at', 'metadata', |
| 19 | ]; |
| 20 | |
| 21 | protected function casts(): array |
| 22 | { |
| 23 | return [ |
| 24 | 'discount_percentage' => 'decimal:2', |
| 25 | 'status' => CouponStatus::class, |
| 26 | 'started_at' => 'datetime', |
| 27 | 'ended_at' => 'datetime', |
| 28 | 'metadata' => 'array', |
| 29 | ]; |
| 30 | } |
| 31 | |
| 32 | public static function normalize(string $code): string |
| 33 | { |
| 34 | return strtoupper(trim($code)); |
| 35 | } |
| 36 | |
| 37 | public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); } |
| 38 | public function store(): BelongsTo { return $this->belongsTo(Store::class); } |
| 39 | public function influencer(): BelongsTo { return $this->belongsTo(Influencer::class); } |
| 40 | public function integration(): BelongsTo { return $this->belongsTo(StoreIntegration::class, 'store_integration_id'); } |
| 41 | public function orders(): HasMany { return $this->hasMany(Order::class, 'coupon_id'); } |
| 42 | } |