Skip to content

Commit 15b1465

Browse files
jrfnlsirbrillig
authored andcommitted
VariableAnalysisSniff::checkForPassByReferenceFunctionCall(): fix comment tolerance (#159)
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 e5bee2d commit 15b1465

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ protected function checkForPassByReferenceFunctionCall(File $phpcsFile, $stackPt
10751075
if ($ptr === $stackPtr) {
10761076
continue;
10771077
}
1078-
if ($tokens[$ptr]['code'] !== T_WHITESPACE) {
1078+
if (isset(Tokens::$emptyTokens[$tokens[$ptr]['code']]) === false) {
10791079
return false;
10801080
}
10811081
}

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function function_with_pass_by_reference_calls() {
3232
echo $matches;
3333
echo $needle;
3434
echo $haystack;
35-
preg_match('/(abc)/', 'defabcghi', $matches);
35+
preg_match('/(abc)/', 'defabcghi', /* comment */ $matches);
3636
preg_match($needle, 'defabcghi', $matches);
3737
preg_match('/(abc)/', $haystack, $matches);
3838
echo $matches;

0 commit comments

Comments
 (0)