Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Enum_\EnumCaseToPascalCaseRector\Fixture;

enum SkipExistingPascal
{
case Pending;
case Published;
case InReview;
case WaitingForApproval;
}
15 changes: 13 additions & 2 deletions rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,18 @@ private function refactorClassConstFetch(ClassConstFetch $classConstFetch): ?Nod

private function convertToPascalCase(string $name): string
{
$parts = explode('_', strtolower($name));
return implode('', array_map(ucfirst(...), $parts));
$parts = explode('_', $name);
return implode(
'',
array_map(
fn ($part): string =>
// If part is all uppercase, convert to ucfirst(strtolower())
// If part is already mixed or PascalCase, keep as is except ucfirst
ctype_upper((string) $part)
? ucfirst(strtolower((string) $part))
: ucfirst((string) $part),
$parts
)
);
}
}
Loading