Skip to content

Commit

Permalink
Merge branch 'disallow-multiple-assignments' of https://github.com/ku…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Apr 8, 2021
2 parents 2c41990 + 557756c commit 53b72cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Expand Up @@ -43,7 +43,7 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();

// Ignore default value assignments in function definitions.
$function = $phpcsFile->findPrevious([T_FUNCTION, T_CLOSURE], ($stackPtr - 1), null, false, null, true);
$function = $phpcsFile->findPrevious([T_FUNCTION, T_CLOSURE, T_FN], ($stackPtr - 1), null, false, null, true);
if ($function !== false) {
$opener = $tokens[$function]['parenthesis_opener'];
$closer = $tokens[$function]['parenthesis_closer'];
Expand Down 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 Expand Up @@ -146,6 +146,7 @@ public function process(File $phpcsFile, $stackPtr)

if ($tokens[$varToken]['code'] === T_VARIABLE
|| $tokens[$varToken]['code'] === T_OPEN_TAG
|| $tokens[$varToken]['code'] === T_GOTO_LABEL
|| $tokens[$varToken]['code'] === T_INLINE_THEN
|| $tokens[$varToken]['code'] === T_INLINE_ELSE
|| $tokens[$varToken]['code'] === T_SEMICOLON
Expand Down
Expand Up @@ -87,3 +87,24 @@ $array = [
false => 0
},
];

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

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

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


function () {
$a = false;

some_label:

$b = getB();
};

0 comments on commit 53b72cb

Please sign in to comment.