protected function VariableAnalysisSniff::processScopeClose in Coder 8.2
Called to process the end of a scope.
Note that although triggered by the closing curly brace of the scope, $stackPtr is the scope conditional, not the closing curly brace.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this: token was found.
int $stackPtr The position of the scope conditional.:
Return value
void
1 call to VariableAnalysisSniff::processScopeClose()
- VariableAnalysisSniff::process in coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - Processes this test, when one of its tokens is encountered.
File
- coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php, line 2226
Class
- VariableAnalysisSniff
- Checks the for undefined function variables.
Namespace
DrupalPractice\Sniffs\CodeAnalysisCode
protected function processScopeClose(File $phpcsFile, $stackPtr) {
$scopeInfo = $this
->getScopeInfo($stackPtr, false);
if (is_null($scopeInfo) === true) {
return;
}
foreach ($scopeInfo->variables as $varInfo) {
if ($varInfo->ignoreUnused === true || isset($varInfo->firstRead) === true) {
continue;
}
if ($this->allowUnusedFunctionParameters === true && $varInfo->scopeType === 'param') {
continue;
}
if ($varInfo->passByReference === true && isset($varInfo->lastAssignment) === true) {
// If we're pass-by-reference then it's a common pattern to
// use the variable to return data to the caller, so any
// assignment also counts as "variable use" for the purposes
// of "unused variable" warnings.
continue;
}
if (isset($varInfo->firstDeclared) === true) {
$phpcsFile
->addWarning("Unused %s %s.", $varInfo->firstDeclared, 'UnusedVariable', array(
VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType],
"\${$varInfo->name}",
));
}
else {
if (isset($varInfo->firstInitialized) === true) {
$phpcsFile
->addWarning("Unused %s %s.", $varInfo->firstInitialized, 'UnusedVariable', array(
VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType],
"\${$varInfo->name}",
));
}
}
//end if
}
//end foreach
}