Fork me on GitHub
a Sensio Labs Product

Persian Successor (v3.65.0) edition

Rule unary_operator_spaces

Unary operators should be placed adjacent to their operands.

Configuration

only_dec_inc

Limit to increment and decrement operators.

Allowed types: bool

Default value: false

Examples

Example #1

Default configuration.

--- Original
+++ New
 <?php
-$sample ++;
--- $sample;
-$sample = ! ! $a;
-$sample = ~  $c;
-function & foo(){}
+$sample++;
+--$sample;
+$sample = !!$a;
+$sample = ~$c;
+function &foo(){}

Example #2

With configuration: ['only_dec_inc' => false].

--- Original
+++ New
 <?php
-function foo($a, ...   $b) { return (--   $a) * ($b   ++);}
+function foo($a, ...$b) { return (--$a) * ($b++);}

Example #3

With configuration: ['only_dec_inc' => true].

--- Original
+++ New
 <?php
-function foo($a, ...   $b) { return (--   $a) * ($b   ++);}
+function foo($a, ...   $b) { return (--$a) * ($b++);}

Rule sets

The rule is part of the following rule sets:

References

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.