function VariableAnalysisSniff::processVariableAsCatchBlock
* Process a variable that is being accessed inside a catch block. * * Can be called for any token and will return false if the variable is not * of this type. * *
Parameters
File $phpcsFile: * @param int $stackPtr * @param string $varName * @param int $currScope * * @return bool
1 call to VariableAnalysisSniff::processVariableAsCatchBlock()
- VariableAnalysisSniff::processVariable in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Process a normal variable in the code. * * Most importantly, this function determines if the variable use is a "read" * (using the variable for something) or a "write" (an assignment) or, * sometimes, both at once. * …
File
-
vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php, line 891
Class
Namespace
VariableAnalysis\Sniffs\CodeAnalysisCode
protected function processVariableAsCatchBlock(File $phpcsFile, $stackPtr, $varName, $currScope) {
$tokens = $phpcsFile->getTokens();
// Are we a catch block parameter?
$openPtr = Helpers::findContainingOpeningBracket($phpcsFile, $stackPtr);
if ($openPtr === null) {
return false;
}
$catchPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $openPtr - 1, null, true, null, true);
if ($catchPtr !== false && $tokens[$catchPtr]['code'] === T_CATCH) {
// Scope of the exception var is actually the function, not just the catch block.
$this->markVariableDeclaration($varName, ScopeType::LOCAL, null, $stackPtr, $currScope, true);
$this->markVariableAssignment($varName, $stackPtr, $currScope);
if ($this->allowUnusedCaughtExceptions) {
$varInfo = $this->getOrCreateVariableInfo($varName, $currScope);
$varInfo->ignoreUnused = true;
}
return true;
}
return false;
}