function Helpers::getClosestConditionPositionIfBeforeOtherConditions
* Return true if the token conditions are within an IF/ELSE/ELSEIF block * before they are within a class or function. * *
Parameters
(int|string)[] $conditions: * * @return int|string|null
1 call to Helpers::getClosestConditionPositionIfBeforeOtherConditions()
- VariableAnalysisSniff::processVariableAsAssignment in vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - * Process a variable that is being assigned. * * This will record that the variable has been defined within a scope so that * later we can determine if it it unused and we can guarantee that any * future uses of the variable are not using an…
File
-
vendor/
sirbrillig/ phpcs-variable-analysis/ VariableAnalysis/ Lib/ Helpers.php, line 160
Class
Namespace
VariableAnalysis\LibCode
public static function getClosestConditionPositionIfBeforeOtherConditions(array $conditions) {
$conditionsInsideOut = array_reverse($conditions, true);
if (empty($conditions)) {
return null;
}
$scopeCode = reset($conditionsInsideOut);
$conditionalCodes = [
T_IF,
T_ELSE,
T_ELSEIF,
];
if (in_array($scopeCode, $conditionalCodes, true)) {
return key($conditionsInsideOut);
}
return null;
}