fix casing of enums

This commit is contained in:
Tomas Votruba 2022-06-13 11:04:14 +02:00
parent 6f164da439
commit 332aad337e
4 changed files with 17 additions and 13 deletions

View File

@ -8724,9 +8724,9 @@ Refactor Spatie enum class to native Enum
-class StatusEnum extends Enum
+enum StatusEnum : string
{
+ case draft = 'draft';
+ case published = 'published';
+ case archived = 'archived';
+ case DRAFT = 'draft';
+ case PUBLISHED = 'published';
+ case ARCHIVED = 'archived';
}
```

View File

@ -23,9 +23,9 @@ use Spatie\Enum\Enum;
enum StatusEnum : string
{
case draft = 'draft';
case published = 'published';
case archived = 'archived';
case DRAFT = 'draft';
case PUBLISHED = 'published';
case ARCHIVED = 'archived';
}
?>

View File

@ -55,10 +55,10 @@ final class EnumFactory
$enum = new Enum_($shortClassName);
// constant to cases
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($class);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);
$docBlockMethods = $phpDocInfo?->getTagsByName('@method');
if ($docBlockMethods !== null) {
$docBlockMethods = $phpDocInfo->getTagsByName('@method');
if ($docBlockMethods !== []) {
$enum->scalarType = new Identifier('string');
foreach ($docBlockMethods as $docBlockMethod) {
@ -85,6 +85,10 @@ final class EnumFactory
{
/** @var MethodTagValueNode $nodeValue */
$nodeValue = $phpDocTagNode->value;
return new EnumCase($nodeValue->methodName, $this->builderFactory->val($nodeValue->methodName));
$enumName = strtoupper($nodeValue->methodName);
$enumExpr = $this->builderFactory->val($nodeValue->methodName);
return new EnumCase($enumName, $enumExpr);
}
}

View File

@ -54,9 +54,9 @@ CODE_SAMPLE
<<<'CODE_SAMPLE'
enum StatusEnum : string
{
case draft = 'draft';
case published = 'published';
case archived = 'archived';
case DRAFT = 'draft';
case PUBLISHED = 'published';
case ARCHIVED = 'archived';
}
CODE_SAMPLE
),