Skip to content

Commit 0bd16bc

Browse files
authored
VariableAnalysisSniff::checkForFunctionPrototype(): fix comment tolerance in pass by reference declaration (#144)
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 58e9681 commit 0bd16bc

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
@@ -479,7 +479,7 @@ protected function checkForFunctionPrototype(File $phpcsFile, $stackPtr, $varNam
479479
) {
480480
$this->markVariableDeclaration($varName, 'param', null, $stackPtr, $functionPtr);
481481
// Are we pass-by-reference?
482-
$referencePtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true);
482+
$referencePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true, null, true);
483483
if (($referencePtr !== false) && ($tokens[$referencePtr]['code'] === T_BITWISE_AND)) {
484484
$varInfo = $this->getOrCreateVariableInfo($varName, $functionPtr);
485485
$varInfo->passByReference = true;

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function function_with_pass_by_reference_calls() {
5050
echo $var3;
5151
}
5252

53-
function function_with_pass_by_ref_assign_only_arg(&$return_value) {
53+
function function_with_pass_by_ref_assign_only_arg(& /*comment*/ $return_value) {
5454
$return_value = 42;
5555
}
5656

0 commit comments

Comments
 (0)