/** * {@inheritdoc} */ public function fix(\SplFileInfo $file, Tokens $tokens) { $tokensAnalyzer = new TokensAnalyzer($tokens); for ($index = $tokens->count() - 1; $index >= 0; --$index) { if (!$tokensAnalyzer->isBinaryOperator($index)) { continue; } if (!$tokens[$index + 1]->isWhitespace()) { $tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' '))); } if (!$tokens[$index - 1]->isWhitespace()) { $tokens->insertAt($index, new Token(array(T_WHITESPACE, ' '))); } } }
/** * @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)); } } }