Skip to content

Commit e5bee2d

Browse files
jrfnlsirbrillig
authored andcommitted
VariableAnalysisSniff::checkForAssignment(): fix comment tolerance (#157)
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 2a1bf60 commit e5bee2d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,9 @@ protected function checkForAssignment(File $phpcsFile, $stackPtr, $varName, $cur
763763

764764
// Are we are reference variable?
765765
$tokens = $tokens = $phpcsFile->getTokens();
766-
$referencePtr = $phpcsFile->findNext(T_WHITESPACE, $assignPtr + 1, null, true, null, true);
766+
$referencePtr = $phpcsFile->findNext(Tokens::$emptyTokens, $assignPtr + 1, null, true, null, true);
767767
$varInfo = $this->getOrCreateVariableInfo($varName, $currScope);
768-
if (($referencePtr !== false) && ($tokens[$referencePtr]['code'] === T_BITWISE_AND)) {
768+
if ($referencePtr !== false && $tokens[$referencePtr]['code'] === T_BITWISE_AND) {
769769
$varInfo->isReference = true;
770770
} elseif ($varInfo->isReference) {
771771
// If this is an assigment to a reference variable then that variable is

VariableAnalysis/Tests/CodeAnalysis/fixtures/AssignmentByReferenceFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function &getProp() {
1515
function usedAssignmentByReference() {
1616
$a = new A();
1717

18-
$var = &$a->getProp();
18+
$var = /*comment*/ &$a->getProp();
1919
$var = ['bar'];
2020
return $a;
2121
}

0 commit comments

Comments
 (0)