protected function VariableAnalysisSniff::checkForThisWithinClass in Coder 8.2
Checks if $this is used within a class.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile:
int $stackPtr:
string $varName:
string $currScope:
Return value
bool
2 calls to VariableAnalysisSniff::checkForThisWithinClass()
- VariableAnalysisSniff::processVariable in coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - Called to process normal member vars.
- VariableAnalysisSniff::processVariableInString in coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - Called to process variables found in double quoted strings.
File
- coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php, line 1390
Class
- VariableAnalysisSniff
- Checks the for undefined function variables.
Namespace
DrupalPractice\Sniffs\CodeAnalysisCode
protected function checkForThisWithinClass(File $phpcsFile, $stackPtr, $varName, $currScope) {
$tokens = $phpcsFile
->getTokens();
$token = $tokens[$stackPtr];
// Are we $this within a class?
if ($varName !== 'this' || empty($token['conditions']) === true) {
return false;
}
foreach (array_reverse($token['conditions'], true) as $scopePtr => $scopeCode) {
if ($scopeCode === T_CLASS || $scopeCode === T_TRAIT) {
return true;
}
}
return false;
}