Skip to content

Commit c8241b9

Browse files
jrfnlsirbrillig
authored andcommitted
VariableAnalysisSniff::checkForFunctionPrototype(): fix comment tolerance in closure use by reference (#145)
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 27eaaaa commit c8241b9

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
@@ -507,7 +507,7 @@ protected function checkForFunctionPrototype(File $phpcsFile, $stackPtr, $varNam
507507
$this->markVariableAssignment($varName, $stackPtr, $functionPtr);
508508

509509
// Are we pass-by-reference?
510-
$referencePtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true);
510+
$referencePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true, null, true);
511511
if ((! is_bool($referencePtr)) && ($tokens[$referencePtr]['code'] === T_BITWISE_AND)) {
512512
$varInfo = $this->getOrCreateVariableInfo($varName, $functionPtr);
513513
$varInfo->passByReference = true;

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithUseReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
$ref = 0;
44

5-
$function_with_use_reference = function () use (&$ref) {
5+
$function_with_use_reference = function () use (& /*comment */ $ref) {
66
$ref = 1;
77
};

0 commit comments

Comments
 (0)