Skip to content

Commit 85c3729

Browse files
committed
Add hasAssignmentToken
1 parent fb1275c commit 85c3729

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

VariableAnalysis/Lib/Helpers.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,23 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr)
382382
return $argPtrs;
383383
}
384384

385+
/**
386+
* Compatibility handler for phpcs 3.x/4.x
387+
* @param array $tokens
388+
* @param int $tokenIndex
389+
* @return bool
390+
*/
391+
private static function hasAssignmentToken($tokens, $tokenIndex)
392+
{
393+
if (isset(Tokens::ASSIGNMENT_TOKENS[$tokens[$tokenIndex]['code']])) {
394+
return true;
395+
}
396+
if (isset(Tokens::$assignmentTokens[$tokens[$tokenIndex]['code']])) {
397+
return true;
398+
}
399+
return false;
400+
}
401+
385402
/**
386403
* @param File $phpcsFile
387404
* @param int $stackPtr
@@ -395,7 +412,7 @@ public static function getNextAssignPointer(File $phpcsFile, $stackPtr)
395412
// Is the next non-whitespace an assignment?
396413
$nextPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
397414
if (is_int($nextPtr)
398-
&& isset(Tokens::$assignmentTokens[$tokens[$nextPtr]['code']])
415+
&& self::hasAssignmentToken($tokens, $nextPtr)
399416
// Ignore double arrow to prevent triggering on `foreach ( $array as $k => $v )`.
400417
&& $tokens[$nextPtr]['code'] !== T_DOUBLE_ARROW
401418
) {

0 commit comments

Comments
 (0)