Skip to content

Commit

Permalink
Always use array for first arg of findPrevious/Next (#131)
Browse files Browse the repository at this point in the history
Not sure why phpstan is complaining about this now, but it seems to hink
that T_OPEN_SHORT_ARRAY, etc, are strings rather than integers. Doing
this makes it quiet down.

This should have no real effect.
  • Loading branch information
sirbrillig authored Feb 11, 2020
1 parent 984a0ae commit 5be26b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions VariableAnalysis/Lib/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function getIntOrNull($value) {
*/
public static function findContainingOpeningSquareBracket(File $phpcsFile, $stackPtr) {
$previousStatementPtr = self::getPreviousStatementPtr($phpcsFile, $stackPtr);
return self::getIntOrNull($phpcsFile->findPrevious(T_OPEN_SHORT_ARRAY, $stackPtr - 1, $previousStatementPtr));
return self::getIntOrNull($phpcsFile->findPrevious([T_OPEN_SHORT_ARRAY], $stackPtr - 1, $previousStatementPtr));
}

/**
Expand All @@ -37,7 +37,7 @@ public static function findContainingClosingSquareBracket(File $phpcsFile, $stac
if (! $endOfStatementPtr) {
return null;
}
return self::getIntOrNull($phpcsFile->findNext(T_CLOSE_SHORT_ARRAY, $stackPtr + 1, $endOfStatementPtr));
return self::getIntOrNull($phpcsFile->findNext([T_CLOSE_SHORT_ARRAY], $stackPtr + 1, $endOfStatementPtr));
}

/**
Expand Down Expand Up @@ -196,15 +196,15 @@ public static function findFunctionCallArguments(File $phpcsFile, $stackPtr) {
$argPtrs = [];
$lastPtr = $openPtr;
$lastArgComma = $openPtr;
$nextPtr = $phpcsFile->findNext(T_COMMA, $lastPtr + 1, $closePtr);
$nextPtr = $phpcsFile->findNext([T_COMMA], $lastPtr + 1, $closePtr);
while (is_int($nextPtr)) {
if (Helpers::findContainingOpeningBracket($phpcsFile, $nextPtr) == $openPtr) {
// Comma is at our level of brackets, it's an argument delimiter.
array_push($argPtrs, range($lastArgComma + 1, $nextPtr - 1));
$lastArgComma = $nextPtr;
}
$lastPtr = $nextPtr;
$nextPtr = $phpcsFile->findNext(T_COMMA, $lastPtr + 1, $closePtr);
$nextPtr = $phpcsFile->findNext([T_COMMA], $lastPtr + 1, $closePtr);
}
array_push($argPtrs, range($lastArgComma + 1, $closePtr - 1));

Expand All @@ -226,8 +226,8 @@ public static function findWhereAssignExecuted(File $phpcsFile, $stackPtr) {
// However, if we're within a bracketed expression, we take place at the
// closing bracket, if that's first.
// eg: echo (($var = 12) && ($var == 12));
$semicolonPtr = $phpcsFile->findNext(T_SEMICOLON, $stackPtr + 1, null, false, null, true);
$commaPtr = $phpcsFile->findNext(T_COMMA, $stackPtr + 1, null, false, null, true);
$semicolonPtr = $phpcsFile->findNext([T_SEMICOLON], $stackPtr + 1, null, false, null, true);
$commaPtr = $phpcsFile->findNext([T_COMMA], $stackPtr + 1, null, false, null, true);
$closePtr = false;
$openPtr = Helpers::findContainingOpeningBracket($phpcsFile, $stackPtr);
if ($openPtr !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function isGetDefinedVars(File $phpcsFile, $stackPtr) {
return false;
}
// Make sure this is a function call
$parenPointer = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, $stackPtr + 2);
$parenPointer = $phpcsFile->findNext([T_OPEN_PARENTHESIS], $stackPtr, $stackPtr + 2);
if (! $parenPointer) {
return false;
}
Expand Down Expand Up @@ -500,7 +500,7 @@ protected function checkForFunctionPrototype(File $phpcsFile, $stackPtr, $varNam
return true;
}
// $functionPtr is at the use, we need the function keyword for start of scope.
$functionPtr = $phpcsFile->findPrevious(T_CLOSURE, $functionPtr - 1, $currScope + 1, false, null, true);
$functionPtr = $phpcsFile->findPrevious([T_CLOSURE], $functionPtr - 1, $currScope + 1, false, null, true);
if (! is_bool($functionPtr)) {
$this->markVariableDeclaration($varName, 'bound', null, $stackPtr, $functionPtr);
$this->markVariableAssignment($varName, $stackPtr, $functionPtr);
Expand Down Expand Up @@ -684,7 +684,7 @@ protected function checkForStaticMember(File $phpcsFile, $stackPtr, $varName, $c
}
// "When calling static methods, the function call is stronger than the
// static property operator" so look for a function call.
$parenPointer = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, $stackPtr + 2);
$parenPointer = $phpcsFile->findNext([T_OPEN_PARENTHESIS], $stackPtr, $stackPtr + 2);
if ($parenPointer) {
return false;
}
Expand Down

0 comments on commit 5be26b4

Please sign in to comment.