Conversation
* Add some more variations to the pre-existing tests:
- Non-lowercase function call(s).
- Fully qualified function calls.
- Use PHP 7.3+ trailing comma's in a few function calls.
* Add tests for some edge-cases (empty text string, parse error).
* Add tests with a few additional PHP syntaxes to document these are handled correctly.
…rals 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.
The PHPCSUtils `PassedParameters::getParameters()` return value includes a `'clean'` array index, which contains the contents of the parameter stripped of surrounding whitespace and comments.
The `LowExpiryCacheTime` sniff uses the parameter contents in the error message, so using the `clean` value makes for a more readable error message.
Includes updating two pre-existing tests.
Before:
```
76 | WARNING | Cache expiry time could not be determined. Please inspect that the fourth parameter passed to wp_cache_set() evaluates to 300
| | seconds or more. Found: "20 * $time /*comment*/" (WordPressVIPMinimum.Performance.LowExpiryCacheTime.CacheTimeUndetermined)
```
After:
```
76 | WARNING | Cache expiry time could not be determined. Please inspect that the fourth parameter passed to wp_cache_set() evaluates to 300
| | seconds or more. Found: "20 * $time" (WordPressVIPMinimum.Performance.LowExpiryCacheTime.CacheTimeUndetermined)
```
…ction calls using named parameters Includes tests.
GaryJones
approved these changes
Jul 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance/LowExpiryCacheTime: move a parse error test to own test case file
Performance/LowExpiryCacheTime: improve the tests
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, theevalwill result in a fatal error, breaking the sniff (and possibly the PHPCS run).By using the PHPCSUtils
Numbersclass, 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 througheval(), the potential fatal error is avoided.Includes tests.
Performance/LowExpiryCacheTime: cleaner error message
The PHPCSUtils
PassedParameters::getParameters()return value includes a'clean'array index, which contains the contents of the parameter stripped of surrounding whitespace and comments.The
LowExpiryCacheTimesniff uses the parameter contents in the error message, so using thecleanvalue makes for a more readable error message.Includes updating two pre-existing tests.
Before:
After:
Performance/LowExpiryCacheTime: add support for handling PHP 8.0+ function calls using named parameters
Includes tests.
Closes #532