/**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     $tokensAnalyzer = new TokensAnalyzer($tokens);
     for ($index = $tokens->count() - 1; $index >= 0; --$index) {
         $token = $tokens[$index];
         if ($tokensAnalyzer->isUnaryPredecessorOperator($index) && $token->equals('!')) {
             if (!$tokens[$index + 1]->isWhitespace()) {
                 $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
             } else {
                 $tokens[$index + 1]->setContent(' ');
             }
         }
     }
 }
 /**
  * {@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;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider provideIsBinaryOperator70
  * @requires PHP 7.0
  */
 public function testIsBinaryOperator70($source, array $expected)
 {
     $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source));
     foreach ($expected as $index => $isBinary) {
         $this->assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index));
         if ($isBinary) {
             $this->assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index));
             $this->assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index));
         }
     }
 }