Skip to content

Commit

Permalink
fix: LowercaseStaticReferenceFixer - do not change typed constants (P…
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and danog committed Feb 2, 2024
1 parent 9dc4adc commit 56775d8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Casing/LowercaseStaticReferenceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

$prevIndex = $tokens->getPrevMeaningfulToken($index);
if ($tokens[$prevIndex]->isGivenKind([T_CONST, T_DOUBLE_COLON, T_FUNCTION, T_NAMESPACE, T_NS_SEPARATOR]) || $tokens[$prevIndex]->isObjectOperator()) {
if ($tokens[$prevIndex]->isGivenKind([T_CONST, T_DOUBLE_COLON, T_FUNCTION, T_NAMESPACE, T_NS_SEPARATOR, T_STATIC, T_STRING, CT::T_ARRAY_TYPEHINT, CT::T_DISJUNCTIVE_NORMAL_FORM_TYPE_PARENTHESIS_CLOSE]) || $tokens[$prevIndex]->isObjectOperator()) {
continue;
}

Expand Down
52 changes: 52 additions & 0 deletions tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,56 @@ public static function provideFix81Cases(): iterable
'<?php enum Foo: string { case PARENT = \'parent\'; }',
];
}

/**
* @dataProvider provideFix83Cases
*
* @requires PHP 8.3
*/
public function testFix83(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<array{0: string, 1?: null|string}>
*/
public static function provideFix83Cases(): iterable
{
yield [<<<'PHP'
<?php
class Foo {
private const array PARENT = ['parent'];
private const array SELF = ['self'];
private const array STATIC = ['static'];
}
PHP];

yield [<<<'PHP'
<?php
class Foo {
private const int PARENT = 1;
private const int SELF = 2;
private const int STATIC = 3;
}
PHP];

yield [<<<'PHP'
<?php
class Foo {
private const int|static PARENT = 1;
private const int|static SELF = 2;
private const int|static STATIC = 3;
}
PHP];

yield [<<<'PHP'
<?php
class Foo {
private const string|(Bar&Baz) PARENT = 'parent';
private const string|(Bar&Baz) SELF = 'self';
private const string|(Bar&Baz) STATIC = 'static';
}
PHP];
}
}

0 comments on commit 56775d8

Please sign in to comment.