-
-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Description
Describe the bug
During the review of #235, @jrfnl noticed that the Generic.CodeAnalysis.ForLoopWithTestFunctionCall
sniff doesn't trigger a warning when a function is called in the test part of the for loop using a variable variable. This is a valid way to call a function, so the warning should be triggered.
Code sample
<?php
for ($i = 0; $i < ${$functionName}(); $i++) {}
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above. - Run
phpcs --standard=Generic --sniffs=Generic.CodeAnalysis.ForLoopWithTestFunctionCall test.php
- PHPCS doesn't report any warnings.
$ bin/phpcs --standard=Generic --sniffs=Generic.CodeAnalysis.ForLoopWithTestFunctionCall test.php
$
Expected behavior
The sniff triggers the Avoid function calls in a FOR loop test part
warning.
Versions (please complete the following information)
Operating System | Ubuntu 23.04 |
PHP version | 8.3 |
PHP_CodeSniffer version | master |
Standard | Generic |
Install type | git clone |
Please confirm:
- I have searched the issue list and am not opening a duplicate issue.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.