Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
52.00% |
13 / 25 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
| PaymentStatus | |
52.00% |
13 / 25 |
|
20.00% |
1 / 5 |
75.53 | |
0.00% |
0 / 1 |
| values | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fromStored | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| icon | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
7.77 | |||
| color | |
75.00% |
6 / 8 |
|
0.00% |
0 / 1 |
7.77 | |||
| badgeClass | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Enums; |
| 4 | |
| 5 | /** |
| 6 | * §5.1 of PROJECT_BRAIN.md. Separate from OrderStatus (the delivery |
| 7 | * lifecycle) — a Pending-delivery order can be Paid, and a Delivered order |
| 8 | * can still be Pending on payment (COD). `payments.status` stays a plain |
| 9 | * string column, same reasoning as OrderStatus. |
| 10 | */ |
| 11 | enum PaymentStatus: string |
| 12 | { |
| 13 | case Pending = 'Pending'; |
| 14 | case Processing = 'Processing'; |
| 15 | case Paid = 'Paid'; |
| 16 | case Failed = 'Failed'; |
| 17 | case Cancelled = 'Cancelled'; |
| 18 | case Refunded = 'Refunded'; |
| 19 | |
| 20 | /** @return string[] */ |
| 21 | public static function values(): array |
| 22 | { |
| 23 | return array_map(fn (self $c) => $c->value, self::cases()); |
| 24 | } |
| 25 | |
| 26 | public static function fromStored(?string $value): self |
| 27 | { |
| 28 | return self::tryFrom((string) $value) ?? self::Pending; |
| 29 | } |
| 30 | |
| 31 | public function icon(): string |
| 32 | { |
| 33 | return match ($this) { |
| 34 | self::Pending => 'fa-clock', |
| 35 | self::Processing => 'fa-spinner', |
| 36 | self::Paid => 'fa-check-circle', |
| 37 | self::Failed => 'fa-times-circle', |
| 38 | self::Cancelled => 'fa-ban', |
| 39 | self::Refunded => 'fa-rotate-left', |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | public function color(): string |
| 44 | { |
| 45 | return match ($this) { |
| 46 | self::Pending => '#f97316', |
| 47 | self::Processing => '#8b5cf6', |
| 48 | self::Paid => '#22c55e', |
| 49 | self::Failed => '#ef4444', |
| 50 | self::Cancelled => '#64748b', |
| 51 | self::Refunded => '#f59e0b', |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | public function badgeClass(): string |
| 56 | { |
| 57 | return match ($this) { |
| 58 | self::Pending => 'bg-warning text-dark', |
| 59 | self::Processing => 'bg-info text-dark', |
| 60 | self::Paid => 'bg-success', |
| 61 | self::Failed, self::Cancelled => 'bg-danger', |
| 62 | self::Refunded => 'bg-secondary', |
| 63 | }; |
| 64 | } |
| 65 | } |