Skip to content

Commit d395525

Browse files
committed
The PHP 7.4 numeric separator backfill now works correctly for more float formats (ref #2546)
1 parent 0786865 commit d395525

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
</stability>
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
29+
- The PHP 7.4 numeric separator backfill now works correctly for more float formats
2930
- Fixed bug #2688 : Case statements not tokenized correctly when switch is contained within ternary
3031
- Fixed bug #2698 : PHPCS throws errors determining auto report width when shell_exec is disabled
3132
-- Thanks to Matthew Peveler for the patch

src/Tokenizers/PHP.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,10 @@ protected function tokenize($string)
10051005
// Support floats.
10061006
if ($tokens[$i][0] === T_STRING
10071007
&& substr(strtolower($tokens[$i][1]), -1) === 'e'
1008-
&& $tokens[($i + 1)] === '-'
1008+
&& ($tokens[($i + 1)] === '-'
1009+
|| $tokens[($i + 1)] === '+')
10091010
) {
1010-
$newContent .= '-';
1011+
$newContent .= $tokens[($i + 1)];
10111012
$i++;
10121013
}
10131014

tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ $foo = 1_000_000_000;
99
/* testFloat */
1010
$foo = 6.674_083e-11;
1111

12+
/* testFloat2 */
13+
$foo = 6.674_083e+11;
14+
1215
/* testHex */
1316
$foo = 0xCAFE_F00D;
1417

tests/Core/Tokenizer/BackfillNumericSeparatorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public function dataTestBackfill()
6565
'value' => '6.674_083e-11',
6666
],
6767
],
68+
[
69+
[
70+
'marker' => '/* testFloat2 */',
71+
'type' => T_DNUMBER,
72+
'value' => '6.674_083e+11',
73+
],
74+
],
6875
[
6976
[
7077
'marker' => '/* testHex */',

0 commit comments

Comments
 (0)