PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer::isInConditional PHP Method

isInConditional() private method

private isInConditional ( Tokens $tokens, integer $index, integer $lowerLimitIndex ) : boolean
$tokens PhpCsFixer\Tokenizer\Tokens
$index integer Index of the token to check
$lowerLimitIndex integer Lower limit index. Since the token to check will always be in a conditional we must stop checking at this index
return boolean
    private function isInConditional(Tokens $tokens, $index, $lowerLimitIndex)
    {
        $candidateIndex = $tokens->getPrevTokenOfKind($index, array(')', ';', ':'));
        if ($tokens[$candidateIndex]->equals(':')) {
            return true;
        }
        if (!$tokens[$candidateIndex]->equals(')')) {
            return false;
            // token is ';' or close tag
        }
        // token is always ')' here.
        // If it is part of the condition the token is always in, return false.
        // If it is not it is a nested condition so return true
        $open = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $candidateIndex, false);
        return $tokens->getPrevMeaningfulToken($open) > $lowerLimitIndex;
    }