fix(enum): memisahkan method comment dan values ke trait supaya reusable

-menghapus return type
-menyesuaikan value color dan label
This commit is contained in:
Yoga Pangestu 2025-09-24 19:25:35 +07:00
parent 1fd4cafb3d
commit 6317037796
4 changed files with 43 additions and 56 deletions

View File

@ -2,37 +2,32 @@
namespace App\Enums; namespace App\Enums;
use App\Traits\WithCommentEnum;
use App\Traits\WithValueEnum;
enum EmploymentStatus: int enum EmploymentStatus: int
{ {
use WithCommentEnum, WithValueEnum;
case PERMANENT = 1; case PERMANENT = 1;
case CONTRACT = 2; case CONTRACT = 2;
case INTERN = 3; case INTERN = 3;
public function label(): string public function label()
{ {
return match ($this) { return match ($this) {
self::PERMANENT => 'Permanent', self::PERMANENT => 'Permanen',
self::CONTRACT => 'Contract', self::CONTRACT => 'Kontrak',
self::INTERN => 'Intern', self::INTERN => 'Magang',
}; };
} }
public function color(): string public function color()
{ {
return match ($this) { return match ($this) {
self::PERMANENT => 'primary', self::PERMANENT => 'emerald',
self::CONTRACT => 'warning', self::CONTRACT => 'yellow',
self::INTERN => 'secondary', 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()));
}
} }

View File

@ -2,12 +2,16 @@
namespace App\Enums; namespace App\Enums;
use App\Traits\WithCommentEnum;
use App\Traits\WithValueEnum;
enum Gender: int enum Gender: int
{ {
use WithCommentEnum, WithValueEnum;
case MALE = 1; case MALE = 1;
case FEMALE = 2; case FEMALE = 2;
public function label(): string public function label()
{ {
return match ($this) { return match ($this) {
self::MALE => 'Male', self::MALE => 'Male',
@ -15,7 +19,7 @@ public function label(): string
}; };
} }
public function color(): string public function color()
{ {
return match ($this) { return match ($this) {
self::MALE => 'primary', 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()); return match ($this) {
} self::MALE => 'mars',
self::FEMALE => 'venus',
public static function comment(): string };
{
return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases()));
} }
} }

View File

@ -2,13 +2,18 @@
namespace App\Enums; namespace App\Enums;
use App\Traits\WithCommentEnum;
use App\Traits\WithValueEnum;
enum OutletStatus: int enum OutletStatus: int
{ {
use WithCommentEnum, WithValueEnum;
case OPERATIONAL = 1; case OPERATIONAL = 1;
case UNDER_CONSTRUCTION = 2; case UNDER_CONSTRUCTION = 2;
case TERMINATED = 3; case TERMINATED = 3;
public function label(): string public function label()
{ {
return match ($this) { return match ($this) {
self::OPERATIONAL => 'Operasional', self::OPERATIONAL => 'Operasional',
@ -17,7 +22,7 @@ public function label(): string
}; };
} }
public function color(): string public function color()
{ {
return match ($this) { return match ($this) {
self::OPERATIONAL => 'emerald', self::OPERATIONAL => 'emerald',
@ -26,7 +31,7 @@ public function color(): string
}; };
} }
public function icon(): string public function icon()
{ {
return match ($this) { return match ($this) {
self::OPERATIONAL => 'check-circle', self::OPERATIONAL => 'check-circle',
@ -34,14 +39,4 @@ public function icon(): string
self::TERMINATED => 'x-circle', 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()));
}
} }

View File

@ -2,13 +2,18 @@
namespace App\Enums; namespace App\Enums;
use App\Traits\WithCommentEnum;
use App\Traits\WithValueEnum;
enum UserStatus: int enum UserStatus: int
{ {
use WithCommentEnum, WithValueEnum;
case ACTIVE = 1; case ACTIVE = 1;
case INACTIVE = 2; case INACTIVE = 2;
case SUSPENDED = 3; case SUSPENDED = 3;
public function label(): string public function label()
{ {
return match ($this) { return match ($this) {
self::ACTIVE => 'Aktif', self::ACTIVE => 'Aktif',
@ -17,16 +22,16 @@ public function label(): string
}; };
} }
public function color(): string public function color()
{ {
return match ($this) { return match ($this) {
self::ACTIVE => 'primary', self::ACTIVE => 'emerald',
self::INACTIVE => 'warning', self::INACTIVE => 'yellow',
self::SUSPENDED => 'danger', self::SUSPENDED => 'red',
}; };
} }
public function icon(): string public function icon()
{ {
return match ($this) { return match ($this) {
self::ACTIVE => 'check-circle', self::ACTIVE => 'check-circle',
@ -34,14 +39,4 @@ public function icon(): string
self::SUSPENDED => 'ban', 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()));
}
} }