Skip to content

Commit 58e9681

Browse files
authored
VariableAnalysisSniff::isGetDefinedVars(): fix comment tolerance (#143)
PHP ignores comments in unexpected/unconventional places and so should the sniff. Includes adjusting an existing unit test. Without the fix, the adjusted unit test would cause test failures.
1 parent 2976bca commit 58e9681

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use VariableAnalysis\Lib\Helpers;
99
use PHP_CodeSniffer\Sniffs\Sniff;
1010
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Util\Tokens;
1112

1213
class VariableAnalysisSniff implements Sniff {
1314
/**
@@ -187,8 +188,8 @@ protected function isGetDefinedVars(File $phpcsFile, $stackPtr) {
187188
return false;
188189
}
189190
// Make sure this is a function call
190-
$parenPointer = $phpcsFile->findNext([T_OPEN_PARENTHESIS], $stackPtr, $stackPtr + 2);
191-
if (! $parenPointer) {
191+
$parenPointer = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
192+
if (! $parenPointer || $tokens[$parenPointer]['code'] !== T_OPEN_PARENTHESIS) {
192193
return false;
193194
}
194195
return true;

VariableAnalysis/Tests/CodeAnalysis/fixtures/GetDefinedVarsFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function send_vars_to_method_with_scope_import( $object, $data ) {
2020
return array_map( function( $datum ) use ( $object, $imported_data ) {
2121
$new_data = $object->transform_data( $datum );
2222
echo $undefined_data; // should be a warning
23-
$object->continue_things( get_defined_vars() );
23+
$object->continue_things( get_defined_vars /* comment */ () );
2424
}, $data );
2525
}
2626

0 commit comments

Comments
 (0)