Skip to content

Commit 6a4d03c

Browse files
authored
Helper::getNextAssignPointer(): fix comment tolerance (#135)
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 5be26b4 commit 6a4d03c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public static function getNextAssignPointer(File $phpcsFile, $stackPtr) {
256256
$tokens = $phpcsFile->getTokens();
257257

258258
// Is the next non-whitespace an assignment?
259-
$nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true, null, true);
259+
$nextPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
260260
if (is_int($nextPtr)
261261
&& isset(Tokens::$assignmentTokens[$tokens[$nextPtr]['code']])
262262
// Ignore double arrow to prevent triggering on `foreach ( $array as $k => $v )`.

VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithInlineAssignFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function function_with_inline_assigns() {
44
($var = 12) && $var;
55
echo $var;
66
echo $var2;
7-
while ($var2 = whatever()) {
7+
while ($var2 /*comment*/ = whatever()) {
88
echo $var2;
99
}
1010
echo $var2;

0 commit comments

Comments
 (0)