Unary operators should be placed adjacent to their operands.
You can configure this rule using the following option: only_dec_inc.
Limit to increment and decrement operators.
Allowed types: bool
Default value: false
Default configuration.
--- Original
+++ New
<?php
-$sample ++;
--- $sample;
-$sample = ! ! $a;
-$sample = ~ $c;
-function & foo(){}
+$sample++;
+--$sample;
+$sample = !!$a;
+$sample = ~$c;
+function &foo(){}With configuration: ['only_dec_inc' => false].
--- Original
+++ New
<?php
-function foo($a, ... $b) { return (-- $a) * ($b ++);}
+function foo($a, ...$b) { return (--$a) * ($b++);}With configuration: ['only_dec_inc' => true].
--- Original
+++ New
<?php
-function foo($a, ... $b) { return (-- $a) * ($b ++);}
+function foo($a, ... $b) { return (--$a) * ($b++);}The rule is part of the following rule sets:
@PER (deprecated) with config:
['only_dec_inc' => true]@PER-CS with config:
['only_dec_inc' => true]@PER-CS1.0 (deprecated) with config:
['only_dec_inc' => true]@PER-CS1x0 with config:
['only_dec_inc' => true]@PER-CS2.0 (deprecated) with config:
['only_dec_inc' => true]@PER-CS2x0 with config:
['only_dec_inc' => true]@PER-CS3.0 (deprecated) with config:
['only_dec_inc' => true]@PER-CS3x0 with config:
['only_dec_inc' => true]@PSR12 with config:
['only_dec_inc' => true]
- Fixer class: PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer
- Test class: PhpCsFixer\Tests\Fixer\Operator\UnaryOperatorSpacesFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.