From a8532c2cb9b257327d7b79c41d2cf3b6aba3b714 Mon Sep 17 00:00:00 2001 From: Caleb White Date: Sat, 13 Sep 2025 22:52:35 -0500 Subject: [PATCH 1/2] fix: EnumCaseToPascalCaseRector skips existing pascal case --- .../Fixture/skip_existing_pascal.php.inc | 11 ++++++++++ .../Enum_/EnumCaseToPascalCaseRector.php | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 rules-tests/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector/Fixture/skip_existing_pascal.php.inc diff --git a/rules-tests/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector/Fixture/skip_existing_pascal.php.inc b/rules-tests/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector/Fixture/skip_existing_pascal.php.inc new file mode 100644 index 00000000000..075ae7d5801 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector/Fixture/skip_existing_pascal.php.inc @@ -0,0 +1,11 @@ +isPascalCase($name)) { + return $name; + } + $parts = explode('_', strtolower($name)); return implode('', array_map(ucfirst(...), $parts)); } + + private function isPascalCase(string $name): bool + { + if (! ctype_upper($name[0])) { + return false; + } + + if (str_contains($name, '_')) { + return false; + } + + if (strtoupper($name) === $name) { + return false; + } + + return true; + } } From 2a86213b3828dab9b9e99caa4097750931d928c4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 14 Sep 2025 14:52:30 +0700 Subject: [PATCH 2/2] use existing convertToPascalCase --- .../Enum_/EnumCaseToPascalCaseRector.php | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php b/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php index 6ddf25c777d..7d64f768521 100644 --- a/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php +++ b/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php @@ -187,28 +187,18 @@ private function refactorClassConstFetch(ClassConstFetch $classConstFetch): ?Nod private function convertToPascalCase(string $name): string { - if ($this->isPascalCase($name)) { - return $name; - } - - $parts = explode('_', strtolower($name)); - return implode('', array_map(ucfirst(...), $parts)); - } - - private function isPascalCase(string $name): bool - { - if (! ctype_upper($name[0])) { - return false; - } - - if (str_contains($name, '_')) { - return false; - } - - if (strtoupper($name) === $name) { - return false; - } - - return true; + $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 + ) + ); } }