Skip to content

Commit

Permalink
Squiz.PHP.DisallowMultipleAssignmentsSniff: Fixed false positive when…
Browse files Browse the repository at this point in the history
… assigment is on first line in closure
  • Loading branch information
kukulich committed Apr 8, 2021
1 parent 9ca9a54 commit c19a0f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public function process(File $phpcsFile, $stackPtr)
*/

for ($varToken = ($stackPtr - 1); $varToken >= 0; $varToken--) {
if (in_array($tokens[$varToken]['code'], [T_SEMICOLON, T_OPEN_CURLY_BRACKET], true) === true) {
// We've reached the next statement, so we
// didn't find a variable.
return;
}

// Skip brackets.
if (isset($tokens[$varToken]['parenthesis_opener']) === true && $tokens[$varToken]['parenthesis_opener'] < $varToken) {
$varToken = $tokens[$varToken]['parenthesis_opener'];
Expand All @@ -94,12 +100,6 @@ public function process(File $phpcsFile, $stackPtr)
continue;
}

if ($tokens[$varToken]['code'] === T_SEMICOLON) {
// We've reached the next statement, so we
// didn't find a variable.
return;
}

if ($tokens[$varToken]['code'] === T_VARIABLE) {
// We found our variable.
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ $array = [
];

$arrow_function = fn ($a = null) => $a;

function ($html) {
$regEx = '/regexp/';

return preg_replace_callback($regEx, function ($matches) {
[$all] = $matches;
return $all;
}, $html);
};

0 comments on commit c19a0f5

Please sign in to comment.