1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Fixer\Operator;
- use PhpCsFixer\AbstractFixer;
- use PhpCsFixer\Tokenizer\Tokens;
- use PhpCsFixer\Tokenizer\TokensAnalyzer;
- /**
- * @author Gregor Harlan <gharlan@web.de>
- */
- final class UnaryOperatorSpacesFixer extends AbstractFixer
- {
- /**
- * {@inheritdoc}
- */
- public function isCandidate(Tokens $tokens)
- {
- return true;
- }
- /**
- * {@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;
- }
- }
- }
- /**
- * {@inheritdoc}
- */
- public function getDescription()
- {
- return 'Unary operators should be placed adjacent to their operands.';
- }
- }
|