Binary operators should be surrounded by space as configured.
Default fix strategy.
Allowed values: 'align'
, 'align_by_scope'
, 'align_single_space'
, 'align_single_space_by_scope'
, 'align_single_space_minimal'
, 'align_single_space_minimal_by_scope'
, 'at_least_single_space'
, 'no_space'
, 'single_space'
and null
Default value: 'single_space'
Dictionary of binary operator
=> fix strategy
values that differ from
the default strategy. Supported are: =
, *
, /
, %
, <
, >
,
|
, ^
, +
, -
, &
, &=
, &&
, ||
, .=
, /=
,
=>
, ==
, >=
, ===
, !=
, <>
, !==
, <=
, and
,
or
, xor
, -=
, %=
, *=
, |=
, +=
, <<
, <<=
,
>>
, >>=
, ^=
, **
, **=
, <=>
, ??
and ??=
.
Allowed types: array<string, ?string>
Default value: []
Default configuration.
--- Original
+++ New
<?php
-$a= 1 + $b^ $d !== $e or $f;
+$a = 1 + $b ^ $d !== $e or $f;
With configuration: ['operators' => ['=' => 'align', 'xor' => null]]
.
--- Original
+++ New
<?php
$aa= 1;
-$b=2;
+$b =2;
$c = $d xor $e;
-$f -= 1;
+$f -= 1;
With configuration: ['operators' => ['+=' => 'align_single_space']]
.
--- Original
+++ New
<?php
-$a = $b +=$c;
-$d = $ee+=$f;
+$a = $b += $c;
+$d = $ee += $f;
-$g = $b +=$c;
-$h = $ee+=$f;
+$g = $b += $c;
+$h = $ee += $f;
With configuration: ['operators' => ['===' => 'align_single_space_minimal']]
.
--- Original
+++ New
<?php
-$a = $b===$c;
-$d = $f === $g;
-$h = $i=== $j;
+$a = $b === $c;
+$d = $f === $g;
+$h = $i === $j;
With configuration: ['operators' => ['|' => 'no_space']]
.
--- Original
+++ New
<?php
-$foo = \json_encode($bar, JSON_PRESERVE_ZERO_FRACTION | JSON_PRETTY_PRINT);
+$foo = \json_encode($bar, JSON_PRESERVE_ZERO_FRACTION|JSON_PRETTY_PRINT);
With configuration: ['operators' => ['=>' => 'single_space']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 1,
- "baaaaaaaaaaar" => 11,
+ "foo" => 1,
+ "baaaaaaaaaaar" => 11,
];
With configuration: ['operators' => ['=>' => 'align']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 12,
+ "foo" => 12,
"baaaaaaaaaaar" => 13,
"baz" => 1,
];
With configuration: ['operators' => ['=>' => 'align_by_scope']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 12,
+ "foo" => 12,
"baaaaaaaaaaar" => 13,
- "baz" => 1,
+ "baz" => 1,
];
With configuration: ['operators' => ['=>' => 'align_single_space']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 12,
+ "foo" => 12,
"baaaaaaaaaaar" => 13,
"baz" => 1,
];
With configuration: ['operators' => ['=>' => 'align_single_space_by_scope']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 12,
+ "foo" => 12,
"baaaaaaaaaaar" => 13,
- "baz" => 1,
+ "baz" => 1,
];
With configuration: ['operators' => ['=>' => 'align_single_space_minimal']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 12,
- "baaaaaaaaaaar" => 13,
+ "foo" => 12,
+ "baaaaaaaaaaar" => 13,
"baz" => 1,
];
With configuration: ['operators' => ['=>' => 'align_single_space_minimal_by_scope']]
.
--- Original
+++ New
<?php
$array = [
- "foo" => 12,
- "baaaaaaaaaaar" => 13,
+ "foo" => 12,
+ "baaaaaaaaaaar" => 13,
- "baz" => 1,
+ "baz" => 1,
];
The rule is part of the following rule sets:
@PER with config:
['default' => 'at_least_single_space']
@PER-CS with config:
['default' => 'at_least_single_space']
@PER-CS1.0 with config:
['default' => 'at_least_single_space']
@PER-CS2.0 with config:
['default' => 'at_least_single_space']
@PSR12 with config:
['default' => 'at_least_single_space']
- Fixer class: PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer
- Test class: PhpCsFixer\Tests\Fixer\Operator\BinaryOperatorSpacesFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.