fix(enum): memisahkan method comment dan values ke trait supaya reusable
-menghapus return type -menyesuaikan value color dan label
This commit is contained in:
parent
1fd4cafb3d
commit
6317037796
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user