Repository: PHP-CS-Fixer/PHP-CS-Fixer (PHP)

Issue:
Enum case 'Parent' is renamed to 'parent'
## Bug report

When an enum has a case named 'Parent', it is renamed to 'parent', breaking the enum.

<!--
  Before reporting a bug, make sure PHP CS Fixer is up-to-date.

  Check that the issue is NOT regarded to an applied rule by using the `-vvv` option (will list applied rules) on a minimal code snippet.

  Please describe the problem and provide technical details such as:
   * PHP CS Fixer version and PHP runtime: php-cs-fixer -V
   * the command used to run PHP CS Fixer (run with `-vvv`)
   * the configuration (file) you used
-->

### Config
```php
<?php

return (new PhpCsFixer\Config())
    ->setRules([
        '@Symfony' => true,
    ])
    ->setFinder(
        PhpCsFixer\Finder::create()
            ->in([
                __DIR__.'/app/enums',
            ])
    );
```

### Output
```
PHP CS Fixer 3.13.0 Oliva by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.2
Loaded config default from ".php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
F                                                                                               1 / 1 (100%)
Legend: .-no changes, F-fixed, S-skipped (cached or empty file), I-invalid file syntax (file ignored), E-error
   1) app/enums/Relation.php (lowercase_static_reference)

Fixed all files in 0.037 seconds, 18.000 MB memory used
```

### Code snippet that reproduces the problem

<!--
  Provide a minimal code snippet before running PHP CS Fixer. If relevant,
  also provide the expected output, the actual output and/or the error that
  occurred, if any.
-->

```php
<?php

namespace App\Enums;

enum Relation: string
{
    case Parent = 'parent';
    case Child = 'child';
}
```

#### Diff after fix
```diff
<?php

namespace App\Enums;

enum Relation: string
{
-   case Parent = 'parent';
+   case parent = 'parent';
    case Child = 'child';
}
```


Discussion:
thanks for raising the bug report, @JaZo , it's indeed an issue!
would you like to give it a try and raise a fixing PR? I would be glad to review and merge it!

side note: I enjoy semi-reserved words that acts differently in different context :D
I'm willing to try and raise a PR for this, but I'm afraid I can't find the time to do it in the near future.



Patch:
diff --git a/src/Fixer/Casing/LowercaseStaticReferenceFixer.php b/src/Fixer/Casing/LowercaseStaticReferenceFixer.php
index 770e66a1c5e..830a511d6d6 100644
--- a/src/Fixer/Casing/LowercaseStaticReferenceFixer.php
+++ b/src/Fixer/Casing/LowercaseStaticReferenceFixer.php
@@ -100,6 +100,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
                 continue;
             }
 
+            if ($tokens[$prevIndex]->isGivenKind(T_CASE) && !$tokens[$nextIndex]->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM)) {
+                continue;
+            }
+
             $tokens[$index] = new Token([$token->getId(), $newContent]);
         }
     }


Test patch:
diff --git a/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php b/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php
index fea40bb2c83..cda051b8af8 100644
--- a/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php
+++ b/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php
@@ -184,6 +184,30 @@ public static function provideFixCases(): array
                 private STATIC ?int $baz2;
             }',
             ],
+            [
+                '<?php
+                class Foo { public function bar() {} }
+                class FooChild extends Foo
+                {
+                    public function bar()
+                    {
+                        switch (true) {
+                            case parent::bar():
+                        }
+                    }
+                }',
+                '<?php
+                class Foo { public function bar() {} }
+                class FooChild extends Foo
+                {
+                    public function bar()
+                    {
+                        switch (true) {
+                            case PARENT::bar():
+                        }
+                    }
+                }',
+            ],
         ];
     }
 
@@ -260,5 +284,9 @@ public static function provideFix81Cases(): iterable
         yield [
             '<?php class A { final const PARENT = 42; }',
         ];
+
+        yield [
+            '<?php enum Foo: string { case PARENT = \'parent\'; }',
+        ];
     }
 }