Skip to content

Commit d00e261

Browse files
committed
Support magic constants
1 parent ea5d0bf commit d00e261

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
66
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
77
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
8-
![Tests](https://img.shields.io/badge/tests-3743-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3744-brightgreen.svg)
99
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
1010

1111
[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)

src/Fixer/TypedClassConstantFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
final class TypedClassConstantFixer extends AbstractFixer
2323
{
24-
private const INTEGER_KINDS = [\T_LNUMBER, '+', '-', '*', '(', ')', \T_POW, \T_SL, \T_SR];
24+
private const INTEGER_KINDS = [\T_LNUMBER, '+', '-', '*', '(', ')', \T_POW, \T_SL, \T_SR, \T_LINE];
2525
private const FLOAT_KINDS = [\T_DNUMBER, ...self::INTEGER_KINDS, '/'];
26-
private const STRING_KINDS = [\T_CONSTANT_ENCAPSED_STRING, \T_START_HEREDOC, \T_ENCAPSED_AND_WHITESPACE, \T_END_HEREDOC, \T_LNUMBER, \T_DNUMBER];
26+
private const STRING_KINDS = [\T_CONSTANT_ENCAPSED_STRING, \T_START_HEREDOC, \T_ENCAPSED_AND_WHITESPACE, \T_END_HEREDOC, \T_LNUMBER, \T_DNUMBER, \T_CLASS_C, \T_DIR, \T_FILE, \T_FUNC_C, \T_METHOD_C, \T_NS_C, \T_TRAIT_C];
2727

2828
public function getDefinition(): FixerDefinitionInterface
2929
{

tests/Fixer/TypedClassConstantFixerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,35 @@ public static function provideFixCases(): iterable
184184
PHP,
185185
];
186186

187+
yield 'string as magic constant' => [
188+
<<<'PHP'
189+
<?php class Foo {
190+
public const string C1 = __CLASS__;
191+
public const string C2 = __DIR__;
192+
public const string C3 = __FILE__;
193+
public const string C4 = __FUNCTION__;
194+
public const int C5 = __LINE__;
195+
public const float C5_HALF = __LINE__ / 2;
196+
public const string C6 = __METHOD__;
197+
public const string C7 = __NAMESPACE__;
198+
public const string C8 = __TRAIT__;
199+
}
200+
PHP,
201+
<<<'PHP'
202+
<?php class Foo {
203+
public const C1 = __CLASS__;
204+
public const C2 = __DIR__;
205+
public const C3 = __FILE__;
206+
public const C4 = __FUNCTION__;
207+
public const C5 = __LINE__;
208+
public const C5_HALF = __LINE__ / 2;
209+
public const C6 = __METHOD__;
210+
public const C7 = __NAMESPACE__;
211+
public const C8 = __TRAIT__;
212+
}
213+
PHP,
214+
];
215+
187216
yield 'string as result of concatenations with parentheses' => [
188217
'<?php class Foo { public const string BAR = "A" . 1 . ("B" . 0.25) . "C"; }',
189218
'<?php class Foo { public const BAR = "A" . 1 . ("B" . 0.25) . "C"; }',

0 commit comments

Comments
 (0)