protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $ternaryLevel = 0;

        foreach ($tokens as $index => $token) {
            if ($token->equals('?')) {
                ++$ternaryLevel;

                $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($index);
                $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];

                if ($nextNonWhitespaceToken->equals(':')) {
                    // for `$a ?: $b` remove spaces between `?` and `:`
                    if ($tokens[$index + 1]->isWhitespace()) {
                        $tokens->clearAt($index + 1);
                    }
                } else {
                    // for `$a ? $b : $c` ensure space after `?`
                    $this->ensureWhitespaceExistence($tokens, $index + 1, true);
                }

                // for `$a ? $b : $c` ensure space before `?`
                $this->ensureWhitespaceExistence($tokens, $index - 1, false);

                continue;
            }

            if ($ternaryLevel && $token->equals(':')) {
                // for `$a ? $b : $c` ensure space after `:`
                $this->ensureWhitespaceExistence($tokens, $index + 1, true);

                $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)];

                if (!$prevNonWhitespaceToken->equals('?')) {
                    // for `$a ? $b : $c` ensure space before `:`
                    $this->ensureWhitespaceExistence($tokens, $index - 1, false);
                }

                --$ternaryLevel;
            }
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $ternaryLevel = 0;

        foreach ($tokens as $index => $token) {
            if ($token->equals('?')) {
                ++$ternaryLevel;

                $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($index);
                $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];

                if ($nextNonWhitespaceToken->equals(':')) {
                    
                    if ($tokens[$index + 1]->isWhitespace()) {
                        $tokens->clearAt($index + 1);
                    }
                } else {
                    
                    $this->ensureWhitespaceExistence($tokens, $index + 1, true);
                }

                
                $this->ensureWhitespaceExistence($tokens, $index - 1, false);

                continue;
            }

            if ($ternaryLevel && $token->equals(':')) {
                
                $this->ensureWhitespaceExistence($tokens, $index + 1, true);

                $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)];

                if (!$prevNonWhitespaceToken->equals('?')) {
                    
                    $this->ensureWhitespaceExistence($tokens, $index - 1, false);
                }

                --$ternaryLevel;
            }
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { $ ternaryLevel = 0 ; foreach ( $ tokens as $ index => $ token ) { if ( $ token -> equals ( '?' ) ) { ++ $ ternaryLevel ; $ nextNonWhitespaceIndex = $ tokens -> getNextNonWhitespace ( $ index ) ; $ nextNonWhitespaceToken = $ tokens [ $ nextNonWhitespaceIndex ] ; if ( $ nextNonWhitespaceToken -> equals ( ':' ) ) { // for `$a ?: $b` remove spaces between `?` and `:` if ( $ tokens [ $ index + 1 ] -> isWhitespace ( ) ) { $ tokens -> clearAt ( $ index + 1 ) ; } } else { // for `$a ? $b : $c` ensure space after `?` $ this -> ensureWhitespaceExistence ( $ tokens , $ index + 1 , true ) ; } // for `$a ? $b : $c` ensure space before `?` $ this -> ensureWhitespaceExistence ( $ tokens , $ index - 1 , false ) ; continue ; } if ( $ ternaryLevel && $ token -> equals ( ':' ) ) { // for `$a ? $b : $c` ensure space after `:` $ this -> ensureWhitespaceExistence ( $ tokens , $ index + 1 , true ) ; $ prevNonWhitespaceToken = $ tokens [ $ tokens -> getPrevNonWhitespace ( $ index ) ] ; if ( ! $ prevNonWhitespaceToken -> equals ( '?' ) ) { // for `$a ? $b : $c` ensure space before `:` $ this -> ensureWhitespaceExistence ( $ tokens , $ index - 1 , false ) ; } -- $ ternaryLevel ; } } }
{@inheritdoc}
{