Commit 58578d1
committed
Performance/LowExpiryCacheTime: add support for PHP 7.4+ numeric literals and 8.1+ octal literals
While PHPCS fully supports these syntaxes at the tokenizer level, this sniff includes the contents of the found token in a string which will be run through `eval()`, which means that if the number was originally provided in a PHP 7.4+ syntax and the sniffs are run on PHP 7.2, the `eval` will result in a fatal error, breaking the sniff (and possibly the PHPCS run).
By using the PHPCSUtils `Numbers` class, we can bypass this and retrieve the decimal value of a integer/float, no matter in what syntax the number is provided. If we then use the decimal value in the string which will be run through `eval()`, the potential fatal error is avoided.
Includes tests.1 parent f2367e9 commit 58578d1
1 file changed
Lines changed: 5 additions & 2 deletions
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
107 | | - | |
108 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| |||
0 commit comments