protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $tokensAnalyzer = new TokensAnalyzer($tokens);

        for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
            $token = $tokens[$index];

            if (!$token->isGivenKind([T_INC, T_DEC])) {
                continue;
            }

            if (self::STYLE_PRE === $this->configuration['style'] && $tokensAnalyzer->isUnarySuccessorOperator($index)) {
                $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
                if (!$nextToken->equalsAny([';', ')'])) {
                    continue;
                }

                $startIndex = $this->findStart($tokens, $index);

                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($startIndex)];
                if ($prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
                    $tokens->clearAt($index);
                    $tokens->insertAt($startIndex, clone $token);
                }
            } elseif (self::STYLE_POST === $this->configuration['style'] && $tokensAnalyzer->isUnaryPredecessorOperator($index)) {
                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
                if (!$prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
                    continue;
                }

                $endIndex = $this->findEnd($tokens, $index);

                $nextToken = $tokens[$tokens->getNextMeaningfulToken($endIndex)];
                if ($nextToken->equalsAny([';', ')'])) {
                    $tokens->clearAt($index);
                    $tokens->insertAt($tokens->getNextNonWhitespace($endIndex), clone $token);
                }
            }
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $tokensAnalyzer = new TokensAnalyzer($tokens);

        for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
            $token = $tokens[$index];

            if (!$token->isGivenKind([T_INC, T_DEC])) {
                continue;
            }

            if (self::STYLE_PRE === $this->configuration['style'] && $tokensAnalyzer->isUnarySuccessorOperator($index)) {
                $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
                if (!$nextToken->equalsAny([';', ')'])) {
                    continue;
                }

                $startIndex = $this->findStart($tokens, $index);

                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($startIndex)];
                if ($prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
                    $tokens->clearAt($index);
                    $tokens->insertAt($startIndex, clone $token);
                }
            } elseif (self::STYLE_POST === $this->configuration['style'] && $tokensAnalyzer->isUnaryPredecessorOperator($index)) {
                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
                if (!$prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
                    continue;
                }

                $endIndex = $this->findEnd($tokens, $index);

                $nextToken = $tokens[$tokens->getNextMeaningfulToken($endIndex)];
                if ($nextToken->equalsAny([';', ')'])) {
                    $tokens->clearAt($index);
                    $tokens->insertAt($tokens->getNextNonWhitespace($endIndex), clone $token);
                }
            }
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { $ tokensAnalyzer = new TokensAnalyzer ( $ tokens ) ; for ( $ index = $ tokens -> count ( ) - 1 ; 0 <= $ index ; -- $ index ) { $ token = $ tokens [ $ index ] ; if ( ! $ token -> isGivenKind ( [ T_INC , T_DEC ] ) ) { continue ; } if ( self :: STYLE_PRE === $ this -> configuration [ 'style' ] && $ tokensAnalyzer -> isUnarySuccessorOperator ( $ index ) ) { $ nextToken = $ tokens [ $ tokens -> getNextMeaningfulToken ( $ index ) ] ; if ( ! $ nextToken -> equalsAny ( [ ';' , ')' ] ) ) { continue ; } $ startIndex = $ this -> findStart ( $ tokens , $ index ) ; $ prevToken = $ tokens [ $ tokens -> getPrevMeaningfulToken ( $ startIndex ) ] ; if ( $ prevToken -> equalsAny ( [ ';' , '{' , '}' , [ T_OPEN_TAG ] ] ) ) { $ tokens -> clearAt ( $ index ) ; $ tokens -> insertAt ( $ startIndex , clone $ token ) ; } } elseif ( self :: STYLE_POST === $ this -> configuration [ 'style' ] && $ tokensAnalyzer -> isUnaryPredecessorOperator ( $ index ) ) { $ prevToken = $ tokens [ $ tokens -> getPrevMeaningfulToken ( $ index ) ] ; if ( ! $ prevToken -> equalsAny ( [ ';' , '{' , '}' , [ T_OPEN_TAG ] ] ) ) { continue ; } $ endIndex = $ this -> findEnd ( $ tokens , $ index ) ; $ nextToken = $ tokens [ $ tokens -> getNextMeaningfulToken ( $ endIndex ) ] ; if ( $ nextToken -> equalsAny ( [ ';' , ')' ] ) ) { $ tokens -> clearAt ( $ index ) ; $ tokens -> insertAt ( $ tokens -> getNextNonWhitespace ( $ endIndex ) , clone $ token ) ; } } } }
{@inheritdoc}
{