function VariableAnalysisSniff::getOrCreateVariableInfo
* Returns variable data for a variable at an index. * * The variable will also be added to the list of variables stored in its * scope so that its use or non-use can be reported when those scopes end by * `processScopeClose()`. * *
Parameters
string $varName: * @param int $currScope * * @return VariableInfo
12 calls to VariableAnalysisSniff::getOrCreateVariableInfo()
- VariableAnalysisSniff::isVariableUndefined in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Return true if a variable is defined within a scope. * *
- VariableAnalysisSniff::markVariableAssignment in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Record that a variable has been defined and assigned a value. * * If a variable has been defined within a scope, it will not be marked as * undefined when that variable is later used. If it is not used, it will be * marked as unused when…
- VariableAnalysisSniff::markVariableAssignmentWithoutInitialization in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Record that a variable has been assigned a value. * * Does not record that a variable has been defined, which is the usual state * of affairs. For that, use `markVariableAssignment()`. * * This is useful for assignments to references. * *
- VariableAnalysisSniff::markVariableDeclaration in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Record that a variable has been defined within a scope. * *
- VariableAnalysisSniff::markVariableRead in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Record that a variable has been used within a scope. * * If the variable has not been defined first, this will still mark it used. * To display a warning for undefined variables, use * `markVariableReadAndWarnIfUndefined()`. * *
File
-
vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php, line 448
Class
Namespace
VariableAnalysis\Sniffs\CodeAnalysisCode
protected function getOrCreateVariableInfo($varName, $currScope) {
Helpers::debug("getOrCreateVariableInfo: starting for '{$varName}'");
$scopeInfo = $this->getOrCreateScopeInfo($currScope);
if (isset($scopeInfo->variables[$varName])) {
Helpers::debug("getOrCreateVariableInfo: found variable for '{$varName}'", $scopeInfo->variables[$varName]);
return $scopeInfo->variables[$varName];
}
Helpers::debug("getOrCreateVariableInfo: creating a new variable for '{$varName}' in scope", $scopeInfo);
$scopeInfo->variables[$varName] = new VariableInfo($varName);
$validUnusedVariableNames = empty($this->validUnusedVariableNames) ? [] : Helpers::splitStringToArray('/\\s+/', trim($this->validUnusedVariableNames));
$validUndefinedVariableNames = empty($this->validUndefinedVariableNames) ? [] : Helpers::splitStringToArray('/\\s+/', trim($this->validUndefinedVariableNames));
if (in_array($varName, $validUnusedVariableNames)) {
$scopeInfo->variables[$varName]->ignoreUnused = true;
}
if (!empty($this->ignoreUnusedRegexp) && preg_match($this->ignoreUnusedRegexp, $varName) === 1) {
$scopeInfo->variables[$varName]->ignoreUnused = true;
}
if ($scopeInfo->scopeStartIndex === 0 && $this->allowUndefinedVariablesInFileScope) {
$scopeInfo->variables[$varName]->ignoreUndefined = true;
}
if (in_array($varName, $validUndefinedVariableNames)) {
$scopeInfo->variables[$varName]->ignoreUndefined = true;
}
if (!empty($this->validUndefinedVariableRegexp) && preg_match($this->validUndefinedVariableRegexp, $varName) === 1) {
$scopeInfo->variables[$varName]->ignoreUndefined = true;
}
Helpers::debug("getOrCreateVariableInfo: scope for '{$varName}' is now", $scopeInfo);
return $scopeInfo->variables[$varName];
}