Skip to content

Commit cf89bb2

Browse files
authored
Helper::findFunctionCall[Arguments](): fix comment tolerance (#138)
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 1237ca4 commit cf89bb2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static function findFunctionCall(File $phpcsFile, $stackPtr) {
159159
$openPtr = Helpers::findContainingOpeningBracket($phpcsFile, $stackPtr);
160160
if (is_int($openPtr)) {
161161
// First non-whitespace thing and see if it's a T_STRING function name
162-
$functionPtr = $phpcsFile->findPrevious(T_WHITESPACE, $openPtr - 1, null, true, null, true);
162+
$functionPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $openPtr - 1, null, true, null, true);
163163
if (is_int($functionPtr) && $tokens[$functionPtr]['code'] === T_STRING) {
164164
return $functionPtr;
165165
}
@@ -186,7 +186,7 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr) {
186186
}
187187

188188
// $stackPtr is the function name, find our brackets after it
189-
$openPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true, null, true);
189+
$openPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
190190
if (($openPtr === false) || ($tokens[$openPtr]['code'] !== T_OPEN_PARENTHESIS)) {
191191
return [];
192192
}

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function function_with_pass_by_reference_calls() {
4444
echo $var1;
4545
echo $var2;
4646
echo $var3;
47-
maxdb_stmt_bind_result($stmt, $var1, $var2, $var3);
47+
maxdb_stmt_bind_result /*comment*/ ($stmt, $var1, $var2, $var3);
4848
echo $var1;
4949
echo $var2;
5050
echo $var3;

0 commit comments

Comments
 (0)