-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathOperatorSpacingStandard.xml
More file actions
48 lines (48 loc) · 1.58 KB
/
OperatorSpacingStandard.xml
File metadata and controls
48 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<documentation title="Operator Spacing">
<standard>
<![CDATA[
All binary and ternary (but not unary) operators MUST be preceded and followed by at least one space. This includes all arithmetic, comparison, assignment, bitwise, logical (excluding ! which is unary), string concatenation, type operators, trait operators (insteadof and as), and the single pipe operator (e.g. ExceptionType1 | ExceptionType2 $e).
]]>
</standard>
<code_comparison>
<code title="Valid: At least 1 space used.">
<![CDATA[
if ($a === $b) {
$foo = $bar ?? $a ?? $b;
} elseif ($a > $b) {
$variable = $foo ? 'foo' : 'bar';
}
]]>
</code>
<code title="Invalid: No spacing used.">
<![CDATA[
if ($a===$b) {
$foo=$bar??$a??$b;
} elseif ($a>$b) {
$variable=$foo?'foo':'bar';
}
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
When the "perCompatible" property is set to "3.0" or higher, the requirement for spaces around the single pipe operator in a multi-catch block is changed to a requirement of "no spaces".
]]>
</standard>
<code_comparison>
<code title="Valid: no spaces around the '|' operator in a multi-catch with 'perCompatible=3.0' (or higher).">
<![CDATA[
try {
} catch (Exception|RuntimeException $e) {
}
]]>
</code>
<code title="Invalid: spaces around the '|' operator in a multi-catch with 'perCompatible=3.0' (or higher).">
<![CDATA[
try {
} catch (Exception | RuntimeException $e) {
}
]]>
</code>
</code_comparison>
</documentation>