Skip to content

Commit

Permalink
The PHP 7.4 numeric separator backfill now works correctly for more f…
Browse files Browse the repository at this point in the history
…loat formats (ref #2546)
  • Loading branch information
gsherwood committed Dec 16, 2019
1 parent 0786865 commit d395525
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
</stability>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- The PHP 7.4 numeric separator backfill now works correctly for more float formats
- Fixed bug #2688 : Case statements not tokenized correctly when switch is contained within ternary
- Fixed bug #2698 : PHPCS throws errors determining auto report width when shell_exec is disabled
-- Thanks to Matthew Peveler for the patch
Expand Down
5 changes: 3 additions & 2 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,10 @@ protected function tokenize($string)
// Support floats.
if ($tokens[$i][0] === T_STRING
&& substr(strtolower($tokens[$i][1]), -1) === 'e'
&& $tokens[($i + 1)] === '-'
&& ($tokens[($i + 1)] === '-'
|| $tokens[($i + 1)] === '+')
) {
$newContent .= '-';
$newContent .= $tokens[($i + 1)];
$i++;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Core/Tokenizer/BackfillNumericSeparatorTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ $foo = 1_000_000_000;
/* testFloat */
$foo = 6.674_083e-11;

/* testFloat2 */
$foo = 6.674_083e+11;

/* testHex */
$foo = 0xCAFE_F00D;

Expand Down
7 changes: 7 additions & 0 deletions tests/Core/Tokenizer/BackfillNumericSeparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public function dataTestBackfill()
'value' => '6.674_083e-11',
],
],
[
[
'marker' => '/* testFloat2 */',
'type' => T_DNUMBER,
'value' => '6.674_083e+11',
],
],
[
[
'marker' => '/* testHex */',
Expand Down

0 comments on commit d395525

Please sign in to comment.