$cases */ private function __construct(public readonly string $type, public readonly array $cases) { } /** * @param array|array $backedCases * @param 'int'|'string' $type */ public static function fromCasesWithType(array $backedCases, string $type): self { if (! ($type === 'int' || $type === 'string')) { throw new InvalidArgumentException(sprintf( '"%s" is not a valid type for Enums, only "int" and "string" types are allowed.', $type )); } $cases = []; foreach ($backedCases as $case => $value) { if ($type === 'string') { $value = sprintf("'%s'", $value); } $cases[] = $case . ' = ' . $value; } return new self($type, $cases); } }