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

getPreviousBlock() private method

[0] First is either T_IF, T_ELSE or T_ELSEIF [1] Last is either '}' or ';' / T_CLOSE_TAG for short notation blocks
private getPreviousBlock ( Tokens $tokens, integer $index ) : int[]
$tokens PhpCsFixer\Tokenizer\Tokens
$index integer T_IF, T_ELSE, T_ELSEIF
return int[]
    private function getPreviousBlock(Tokens $tokens, $index)
    {
        $close = $previous = $tokens->getPrevMeaningfulToken($index);
        // short 'if' detection
        if ($tokens[$close]->equals('}')) {
            $previous = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $close, false);
        }
        $open = $tokens->getPrevTokenOfKind($previous, array(array(T_IF), array(T_ELSE), array(T_ELSEIF)));
        if ($tokens[$open]->isGivenKind(T_IF)) {
            $elseCandidate = $tokens->getPrevMeaningfulToken($open);
            if ($tokens[$elseCandidate]->isGivenKind(T_ELSE)) {
                $open = $elseCandidate;
            }
        }
        return array($open, $close);
    }