src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php
private function fixOpenCloseControls($index, Token $token, Tokens $tokens)
    {
        if ($token->isGivenKind([T_IF, T_FOREACH, T_WHILE, T_FOR])) {
            $openIndex = $tokens->getNextTokenOfKind($index, ['(']);
            $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
            $afterParenthesisIndex = $tokens->getNextNonWhitespace($closeIndex);
            $afterParenthesis = $tokens[$afterParenthesisIndex];

            if (!$afterParenthesis->equals(':')) {
                return;
            }
            $items = [];
            if (!$tokens[$afterParenthesisIndex - 1]->isWhitespace()) {
                $items[] = new Token([T_WHITESPACE, ' ']);
            }
            $items[] = new Token('{');

            if (!$tokens[$afterParenthesisIndex + 1]->isWhitespace()) {
                $items[] = new Token([T_WHITESPACE, ' ']);
            }
            $tokens->clearAt($afterParenthesisIndex);
            $tokens->insertAt($afterParenthesisIndex, $items);
        }

        if (!$token->isGivenKind([T_ENDIF, T_ENDFOREACH, T_ENDWHILE, T_ENDFOR])) {
            return;
        }

        $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
        $nextToken = $tokens[$nextTokenIndex];
        $tokens[$index] = new Token('}');
        if ($nextToken->equals(';')) {
            $tokens->clearAt($nextTokenIndex);
        }
    }
private function fixOpenCloseControls($index, Token $token, Tokens $tokens)
    {
        if ($token->isGivenKind([T_IF, T_FOREACH, T_WHILE, T_FOR])) {
            $openIndex = $tokens->getNextTokenOfKind($index, ['(']);
            $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
            $afterParenthesisIndex = $tokens->getNextNonWhitespace($closeIndex);
            $afterParenthesis = $tokens[$afterParenthesisIndex];

            if (!$afterParenthesis->equals(':')) {
                return;
            }
            $items = [];
            if (!$tokens[$afterParenthesisIndex - 1]->isWhitespace()) {
                $items[] = new Token([T_WHITESPACE, ' ']);
            }
            $items[] = new Token('{');

            if (!$tokens[$afterParenthesisIndex + 1]->isWhitespace()) {
                $items[] = new Token([T_WHITESPACE, ' ']);
            }
            $tokens->clearAt($afterParenthesisIndex);
            $tokens->insertAt($afterParenthesisIndex, $items);
        }

        if (!$token->isGivenKind([T_ENDIF, T_ENDFOREACH, T_ENDWHILE, T_ENDFOR])) {
            return;
        }

        $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
        $nextToken = $tokens[$nextTokenIndex];
        $tokens[$index] = new Token('}');
        if ($nextToken->equals(';')) {
            $tokens->clearAt($nextTokenIndex);
        }
    }
private function fixOpenCloseControls ( $ index , Token $ token , Tokens $ tokens ) { if ( $ token -> isGivenKind ( [ T_IF , T_FOREACH , T_WHILE , T_FOR ] ) ) { $ openIndex = $ tokens -> getNextTokenOfKind ( $ index , [ '(' ] ) ; $ closeIndex = $ tokens -> findBlockEnd ( Tokens :: BLOCK_TYPE_PARENTHESIS_BRACE , $ openIndex ) ; $ afterParenthesisIndex = $ tokens -> getNextNonWhitespace ( $ closeIndex ) ; $ afterParenthesis = $ tokens [ $ afterParenthesisIndex ] ; if ( ! $ afterParenthesis -> equals ( ':' ) ) { return ; } $ items = [ ] ; if ( ! $ tokens [ $ afterParenthesisIndex - 1 ] -> isWhitespace ( ) ) { $ items [ ] = new Token ( [ T_WHITESPACE , ' ' ] ) ; } $ items [ ] = new Token ( '{' ) ; if ( ! $ tokens [ $ afterParenthesisIndex + 1 ] -> isWhitespace ( ) ) { $ items [ ] = new Token ( [ T_WHITESPACE , ' ' ] ) ; } $ tokens -> clearAt ( $ afterParenthesisIndex ) ; $ tokens -> insertAt ( $ afterParenthesisIndex , $ items ) ; } if ( ! $ token -> isGivenKind ( [ T_ENDIF , T_ENDFOREACH , T_ENDWHILE , T_ENDFOR ] ) ) { return ; } $ nextTokenIndex = $ tokens -> getNextMeaningfulToken ( $ index ) ; $ nextToken = $ tokens [ $ nextTokenIndex ] ; $ tokens [ $ index ] = new Token ( '}' ) ; if ( $ nextToken -> equals ( ';' ) ) { $ tokens -> clearAt ( $ nextTokenIndex ) ; } }
Handle both extremes of the control structures.
e.g. if(): or endif;.

@param int    $index  the index of the token being processed
@param Token  $token  the token being processed
@param Tokens $tokens the collection of tokens
Handle both extremes of the control structures . e . g . if () : or endif ; .