PhpCsFixer\Tokenizer\TokensAnalyzer::isUnarySuccessorOperator PHP Method

isUnarySuccessorOperator() public method

Checks if there is an unary successor operator under given index.
public isUnarySuccessorOperator ( integer $index ) : boolean
$index integer
return boolean
    public function isUnarySuccessorOperator($index)
    {
        static $allowedPrevToken = array(']', array(T_STRING), array(T_VARIABLE), array(CT::T_DYNAMIC_PROP_BRACE_CLOSE), array(CT::T_DYNAMIC_VAR_BRACE_CLOSE));
        $tokens = $this->tokens;
        $token = $tokens[$index];
        if (!$token->isGivenKind(array(T_INC, T_DEC))) {
            return false;
        }
        $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
        return $prevToken->equalsAny($allowedPrevToken);
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         if ($tokensAnalyzer->isUnarySuccessorOperator($index)) {
             $tokens->removeLeadingWhitespace($index);
             continue;
         }
         if ($tokensAnalyzer->isUnaryPredecessorOperator($index)) {
             $tokens->removeTrailingWhitespace($index);
             continue;
         }
     }
 }
All Usage Examples Of PhpCsFixer\Tokenizer\TokensAnalyzer::isUnarySuccessorOperator