From 6317037796f74686a947461636a47c0e66695cc2 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 24 Sep 2025 19:25:35 +0700 Subject: [PATCH] fix(enum): memisahkan method comment dan values ke trait supaya reusable -menghapus return type -menyesuaikan value color dan label --- app/Enums/EmploymentStatus.php | 31 +++++++++++++------------------ app/Enums/Gender.php | 20 +++++++++++--------- app/Enums/OutletStatus.php | 21 ++++++++------------- app/Enums/UserStatus.php | 27 +++++++++++---------------- 4 files changed, 43 insertions(+), 56 deletions(-) diff --git a/app/Enums/EmploymentStatus.php b/app/Enums/EmploymentStatus.php index 61d55ff..51c9364 100644 --- a/app/Enums/EmploymentStatus.php +++ b/app/Enums/EmploymentStatus.php @@ -2,37 +2,32 @@ namespace App\Enums; +use App\Traits\WithCommentEnum; +use App\Traits\WithValueEnum; + enum EmploymentStatus: int { + use WithCommentEnum, WithValueEnum; + case PERMANENT = 1; case CONTRACT = 2; case INTERN = 3; - public function label(): string + public function label() { return match ($this) { - self::PERMANENT => 'Permanent', - self::CONTRACT => 'Contract', - self::INTERN => 'Intern', + self::PERMANENT => 'Permanen', + self::CONTRACT => 'Kontrak', + self::INTERN => 'Magang', }; } - public function color(): string + public function color() { return match ($this) { - self::PERMANENT => 'primary', - self::CONTRACT => 'warning', - self::INTERN => 'secondary', + self::PERMANENT => 'emerald', + self::CONTRACT => 'yellow', + self::INTERN => 'lime', }; } - - public static function values(): array - { - return array_map(fn ($case) => $case->value, self::cases()); - } - - public static function comment(): string - { - return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases())); - } } diff --git a/app/Enums/Gender.php b/app/Enums/Gender.php index 677a51e..d65bdf9 100644 --- a/app/Enums/Gender.php +++ b/app/Enums/Gender.php @@ -2,12 +2,16 @@ namespace App\Enums; +use App\Traits\WithCommentEnum; +use App\Traits\WithValueEnum; + enum Gender: int { + use WithCommentEnum, WithValueEnum; case MALE = 1; case FEMALE = 2; - public function label(): string + public function label() { return match ($this) { self::MALE => 'Male', @@ -15,7 +19,7 @@ public function label(): string }; } - public function color(): string + public function color() { return match ($this) { self::MALE => 'primary', @@ -23,13 +27,11 @@ public function color(): string }; } - public static function values(): array + public function icon() { - return array_map(fn ($case) => $case->value, self::cases()); - } - - public static function comment(): string - { - return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases())); + return match ($this) { + self::MALE => 'mars', + self::FEMALE => 'venus', + }; } } diff --git a/app/Enums/OutletStatus.php b/app/Enums/OutletStatus.php index 1b38dd2..c792a7e 100644 --- a/app/Enums/OutletStatus.php +++ b/app/Enums/OutletStatus.php @@ -2,13 +2,18 @@ namespace App\Enums; +use App\Traits\WithCommentEnum; +use App\Traits\WithValueEnum; + enum OutletStatus: int { + use WithCommentEnum, WithValueEnum; + case OPERATIONAL = 1; case UNDER_CONSTRUCTION = 2; case TERMINATED = 3; - public function label(): string + public function label() { return match ($this) { self::OPERATIONAL => 'Operasional', @@ -17,7 +22,7 @@ public function label(): string }; } - public function color(): string + public function color() { return match ($this) { self::OPERATIONAL => 'emerald', @@ -26,7 +31,7 @@ public function color(): string }; } - public function icon(): string + public function icon() { return match ($this) { self::OPERATIONAL => 'check-circle', @@ -34,14 +39,4 @@ public function icon(): string self::TERMINATED => 'x-circle', }; } - - public static function values(): array - { - return array_map(fn ($case) => $case->value, self::cases()); - } - - public static function comment(): string - { - return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases())); - } } diff --git a/app/Enums/UserStatus.php b/app/Enums/UserStatus.php index 885e438..87b11b9 100644 --- a/app/Enums/UserStatus.php +++ b/app/Enums/UserStatus.php @@ -2,13 +2,18 @@ namespace App\Enums; +use App\Traits\WithCommentEnum; +use App\Traits\WithValueEnum; + enum UserStatus: int { + use WithCommentEnum, WithValueEnum; + case ACTIVE = 1; case INACTIVE = 2; case SUSPENDED = 3; - public function label(): string + public function label() { return match ($this) { self::ACTIVE => 'Aktif', @@ -17,16 +22,16 @@ public function label(): string }; } - public function color(): string + public function color() { return match ($this) { - self::ACTIVE => 'primary', - self::INACTIVE => 'warning', - self::SUSPENDED => 'danger', + self::ACTIVE => 'emerald', + self::INACTIVE => 'yellow', + self::SUSPENDED => 'red', }; } - public function icon(): string + public function icon() { return match ($this) { self::ACTIVE => 'check-circle', @@ -34,14 +39,4 @@ public function icon(): string self::SUSPENDED => 'ban', }; } - - public static function values(): array - { - return array_map(fn ($case) => $case->value, self::cases()); - } - - public static function comment(): string - { - return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases())); - } }