function EarlyExitSniff::getAllConditionsPointers
*
Return value
list<int>
3 calls to EarlyExitSniff::getAllConditionsPointers()
- EarlyExitSniff::findEarlyExitInScope in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ EarlyExitSniff.php - EarlyExitSniff::processElse in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ EarlyExitSniff.php - EarlyExitSniff::processElseIf in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ EarlyExitSniff.php
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ EarlyExitSniff.php, line 427
Class
Namespace
SlevomatCodingStandard\Sniffs\ControlStructuresCode
private function getAllConditionsPointers(File $phpcsFile, int $conditionPointer) : array {
$tokens = $phpcsFile->getTokens();
$conditionsPointers = [
$conditionPointer,
];
if (isset($tokens[$conditionPointer]['scope_opener']) && $tokens[$tokens[$conditionPointer]['scope_opener']]['code'] === T_COLON) {
// Alternative control structure syntax.
throw new Exception(sprintf('"%s" without curly braces is not supported.', $tokens[$conditionPointer]['content']));
}
if ($tokens[$conditionPointer]['code'] !== T_IF) {
$currentConditionPointer = $conditionPointer;
do {
$previousConditionCloseParenthesisPointer = TokenHelper::findPreviousEffective($phpcsFile, $currentConditionPointer - 1);
$currentConditionPointer = $tokens[$previousConditionCloseParenthesisPointer]['scope_condition'];
$conditionsPointers[] = $currentConditionPointer;
} while ($tokens[$currentConditionPointer]['code'] !== T_IF);
}
if ($tokens[$conditionPointer]['code'] !== T_ELSE) {
if (!array_key_exists('scope_closer', $tokens[$conditionPointer])) {
throw new Exception(sprintf('"%s" without curly braces is not supported.', $tokens[$conditionPointer]['content']));
}
$currentConditionPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$conditionPointer]['scope_closer'] + 1);
if ($currentConditionPointer !== null) {
while (in_array($tokens[$currentConditionPointer]['code'], [
T_ELSEIF,
T_ELSE,
], true)) {
$conditionsPointers[] = $currentConditionPointer;
if (!array_key_exists('scope_closer', $tokens[$currentConditionPointer])) {
throw new Exception(sprintf('"%s" without curly braces is not supported.', $tokens[$currentConditionPointer]['content']));
}
$currentConditionPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$currentConditionPointer]['scope_closer'] + 1);
}
}
}
sort($conditionsPointers);
return $conditionsPointers;
}