Skip to content

Commit 0500066

Browse files
jrfnlsirbrillig
authored andcommitted
VariableAnalysisSniff::checkForListAssignment(): fix comment tolerance (#152)
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 dfdac09 commit 0500066

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
@@ -853,7 +853,7 @@ protected function checkForListAssignment(File $phpcsFile, $stackPtr, $varName,
853853
return false;
854854
}
855855

856-
$prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $openPtr - 1, null, true, null, true);
856+
$prevPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $openPtr - 1, null, true, null, true);
857857
if (($prevPtr === false) || ($tokens[$prevPtr]['code'] !== T_LIST)) {
858858
return false;
859859
}

VariableAnalysis/Tests/CodeAnalysis/fixtures/DestructuringFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function function_with_destructuring_assignment() {
99

1010
function function_with_destructuring_assignment_using_list() {
1111
list( $a, $b ) = [1, 2];
12-
list( $c, $d ) = [3, 4]; // unused
12+
list /* comment */ ( $c, $d ) = [3, 4]; // unused
1313
echo $a;
1414
echo $b;
1515
echo $c;

0 commit comments

Comments
 (0)