src/AbstractNoUselessElseFixer.php
private function isInConditional(Tokens $tokens, $index, $lowerLimitIndex)
    {
        $candidateIndex = $tokens->getPrevTokenOfKind($index, [')', ';', ':']);
        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->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $candidateIndex);

        return $tokens->getPrevMeaningfulToken($open) > $lowerLimitIndex;
    }
private function isInConditional(Tokens $tokens, $index, $lowerLimitIndex)
    {
        $candidateIndex = $tokens->getPrevTokenOfKind($index, [')', ';', ':']);
        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->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $candidateIndex);

        return $tokens->getPrevMeaningfulToken($open) > $lowerLimitIndex;
    }
private function isInConditional ( Tokens $ tokens , $ index , $ lowerLimitIndex ) { $ candidateIndex = $ tokens -> getPrevTokenOfKind ( $ index , [ ')' , ';' , ':' ] ) ; 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 -> findBlockStart ( Tokens :: BLOCK_TYPE_PARENTHESIS_BRACE , $ candidateIndex ) ; return $ tokens -> getPrevMeaningfulToken ( $ open ) > $ lowerLimitIndex ; }
@param Tokens $tokens
@param int    $index           Index of the token to check
@param int    $lowerLimitIndex Lower limit index. Since the token to check will always be in a conditional we must stop checking at this index

@return bool
@param Tokens $tokens @param int $index Index of the token to check @param int $lowerLimitIndex Lower limit index . Since the token to check will always be in a conditional we must stop checking at this index