Skip to content

Commit

Permalink
fix: enum case "PARENT" must not be renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Dec 30, 2022
1 parent fb41eb6 commit c3387f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Fixer/Casing/LowercaseStaticReferenceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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():
}
}
}',
],
];
}

Expand Down Expand Up @@ -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\'; }',
];
}
}

0 comments on commit c3387f7

Please sign in to comment.