Skip to content

Commit 6ba301a

Browse files
authored
[Documentation] PSR12 - Control Structure Spacing (#182)
* Add the documentation for the PSR12 Control Structure Spacing sniff
1 parent b5dc38b commit 6ba301a

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<documentation title="Control Structure Spacing">
2+
<standard>
3+
<![CDATA[
4+
Single line control structures must have no spaces after the condition opening parenthesis and before the condition closing parenthesis.
5+
]]>
6+
</standard>
7+
<code_comparison>
8+
<code title="Valid: No space after the opening parenthesis in a single-line condition.">
9+
<![CDATA[
10+
if <em>(</em>$expr) {
11+
}
12+
]]>
13+
</code>
14+
<code title="Invalid: Space after the opening parenthesis in a single-line condition.">
15+
<![CDATA[
16+
if <em>( </em>$expr) {
17+
}
18+
]]>
19+
</code>
20+
</code_comparison>
21+
<code_comparison>
22+
<code title="Valid: No space before the closing parenthesis in a single-line condition.">
23+
<![CDATA[
24+
if <em>(</em>$expr) {
25+
}
26+
]]>
27+
</code>
28+
<code title="Invalid: Space before the closing parenthesis in a single-line condition.">
29+
<![CDATA[
30+
if ($expr<em> )</em> {
31+
}
32+
]]>
33+
</code>
34+
</code_comparison>
35+
<standard>
36+
<![CDATA[
37+
The condition of the multi-line control structure must be indented once, placing the first expression on the next line after the opening parenthesis.
38+
]]>
39+
</standard>
40+
<code_comparison>
41+
<code title="Valid: First expression of a multi-line control structure condition block is on the line after the opening parenthesis.">
42+
<![CDATA[
43+
while (
44+
<em>$expr1</em>
45+
&& $expr2
46+
) {
47+
}
48+
]]>
49+
</code>
50+
<code title="Invalid: First expression of a multi-line control structure condition block is on the same line as the opening parenthesis.">
51+
<![CDATA[
52+
while <em>($expr1</em>
53+
&& $expr2
54+
) {
55+
}
56+
]]>
57+
</code>
58+
</code_comparison>
59+
<code_comparison>
60+
<code title="Valid: Each line in a multi-line control structure condition block indented at least once. Default indentation is 4 spaces.">
61+
<![CDATA[
62+
while (
63+
<em> </em>$expr1
64+
<em> </em>&& $expr2
65+
) {
66+
}
67+
]]>
68+
</code>
69+
<code title="Invalid: Some lines in a multi-line control structure condition block not indented correctly.">
70+
<![CDATA[
71+
while (
72+
<em>$expr1</em>
73+
&& $expr2
74+
<em> && $expr3</em>
75+
) {
76+
}
77+
]]>
78+
</code>
79+
</code_comparison>
80+
<standard>
81+
<![CDATA[
82+
The closing parenthesis of the multi-line control structure must be on the next line after the last condition, indented to the same level as the start of the control structure.
83+
]]>
84+
</standard>
85+
<code_comparison>
86+
<code title="Valid: The closing parenthesis of a multi-line control structure condition block is on the line after the last expression.">
87+
<![CDATA[
88+
while (
89+
$expr1
90+
&& $expr2
91+
<em>)</em> {
92+
}
93+
]]>
94+
</code>
95+
<code title="Invalid: The closing parenthesis of a multi-line control structure condition block is on the same line as the last expression.">
96+
<![CDATA[
97+
while (
98+
$expr1
99+
<em>&& $expr2)</em> {
100+
}
101+
]]>
102+
</code>
103+
</code_comparison>
104+
<code_comparison>
105+
<code title="Valid: The closing parenthesis of a multi-line control structure condition block is indented to the same level as start of the control structure.">
106+
<![CDATA[
107+
while (
108+
$expr1
109+
&& $expr2
110+
<em>)</em> {
111+
}
112+
]]>
113+
</code>
114+
<code title="Invalid: The closing parenthesis of a multi-line control structure condition block is not indented to the same level as start of the control structure.">
115+
<![CDATA[
116+
while (
117+
$expr1
118+
&& $expr2
119+
<em> )</em> {
120+
}
121+
]]>
122+
</code>
123+
</code_comparison>
124+
</documentation>

0 commit comments

Comments
 (0)