Skip to content

Commit a9f7355

Browse files
authored
Merge pull request #1049 from rodrigoprimo/documentation-switch-declaration
PSR2/SwitchDeclaration: improve XML documentation
2 parents 03359eb + 0ba7490 commit a9f7355

File tree

1 file changed

+117
-17
lines changed

1 file changed

+117
-17
lines changed

src/Standards/PSR2/Docs/ControlStructures/SwitchDeclarationStandard.xml

Lines changed: 117 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
1-
<documentation title="Switch Declarations">
1+
<documentation title="Switch Declaration">
22
<standard>
33
<![CDATA[
4-
Case statements should be indented 4 spaces from the switch keyword. It should also be followed by a space. Colons in switch declarations should not be preceded by whitespace. Break statements should be indented 4 more spaces from the case statement. There must be a comment when falling through from one case into the next.
4+
Case and default keywords must be lowercase.
55
]]>
66
</standard>
77
<code_comparison>
8-
<code title="Valid: Case statement indented correctly.">
8+
<code title="Valid: Keywords in lowercase.">
99
<![CDATA[
1010
switch ($foo) {
11-
<em> </em>case 'bar':
11+
<em>case</em> 'bar':
12+
break;
13+
<em>default</em>:
1214
break;
1315
}
1416
]]>
1517
</code>
16-
<code title="Invalid: Case statement not indented 4 spaces.">
18+
<code title="Invalid: Keywords not in lowercase.">
1719
<![CDATA[
1820
switch ($foo) {
19-
<em></em>case 'bar':
20-
break;
21+
<em>CASE</em> 'bar':
22+
break;
23+
<em>Default</em>:
24+
break;
2125
}
2226
]]>
2327
</code>
2428
</code_comparison>
29+
<standard>
30+
<![CDATA[
31+
Case statements must be followed by exactly one space.
32+
]]>
33+
</standard>
2534
<code_comparison>
26-
<code title="Valid: Case statement followed by 1 space.">
35+
<code title="Valid: Case statement followed by one space.">
2736
<![CDATA[
2837
switch ($foo) {
2938
case<em> </em>'bar':
3039
break;
3140
}
3241
]]>
3342
</code>
34-
<code title="Invalid: Case statement not followed by 1 space.">
43+
<code title="Invalid: Case statement not followed by one space.">
3544
<![CDATA[
3645
switch ($foo) {
3746
case<em></em>'bar':
@@ -40,8 +49,13 @@ switch ($foo) {
4049
]]>
4150
</code>
4251
</code_comparison>
52+
<standard>
53+
<![CDATA[
54+
There must be no whitespace between the case value or default keyword and the colon.
55+
]]>
56+
</standard>
4357
<code_comparison>
44-
<code title="Valid: Colons not prefixed by whitespace.">
58+
<code title="Valid: Colons not preceded by whitespace.">
4559
<![CDATA[
4660
switch ($foo) {
4761
case 'bar'<em></em>:
@@ -51,7 +65,7 @@ switch ($foo) {
5165
}
5266
]]>
5367
</code>
54-
<code title="Invalid: Colons prefixed by whitespace.">
68+
<code title="Invalid: Colons preceded by whitespace.">
5569
<![CDATA[
5670
switch ($foo) {
5771
case 'bar'<em> </em>:
@@ -62,6 +76,57 @@ switch ($foo) {
6276
]]>
6377
</code>
6478
</code_comparison>
79+
<standard>
80+
<![CDATA[
81+
The case or default body must start on the line following the statement.
82+
]]>
83+
</standard>
84+
<code_comparison>
85+
<code title="Valid: Body starts on the next line.">
86+
<![CDATA[
87+
switch ($foo) {
88+
case 'bar':
89+
<em></em> break;
90+
}
91+
]]>
92+
</code>
93+
<code title="Invalid: Body on the same line as the case statement.">
94+
<![CDATA[
95+
switch ($foo) {
96+
case 'bar':<em></em> break;
97+
}
98+
]]>
99+
</code>
100+
</code_comparison>
101+
<standard>
102+
<![CDATA[
103+
Terminating statements must be on a line by themselves.
104+
]]>
105+
</standard>
106+
<code_comparison>
107+
<code title="Valid: Terminating statement on its own line.">
108+
<![CDATA[
109+
switch ($foo) {
110+
case 'bar':
111+
echo $foo;
112+
<em>return;</em>
113+
}
114+
]]>
115+
</code>
116+
<code title="Invalid: Terminating statement not on its own line.">
117+
<![CDATA[
118+
switch ($foo) {
119+
case 'bar':
120+
<em>echo $foo; return;</em>
121+
}
122+
]]>
123+
</code>
124+
</code_comparison>
125+
<standard>
126+
<![CDATA[
127+
Terminating statements must be indented four more spaces from the case statement.
128+
]]>
129+
</standard>
65130
<code_comparison>
66131
<code title="Valid: Break statement indented correctly.">
67132
<![CDATA[
@@ -71,7 +136,7 @@ switch ($foo) {
71136
}
72137
]]>
73138
</code>
74-
<code title="Invalid: Break statement not indented 4 spaces.">
139+
<code title="Invalid: Break statement not indented four spaces.">
75140
<![CDATA[
76141
switch ($foo) {
77142
case 'bar':
@@ -80,22 +145,57 @@ switch ($foo) {
80145
]]>
81146
</code>
82147
</code_comparison>
148+
<standard>
149+
<![CDATA[
150+
Case and default statements must be defined using a colon.
151+
]]>
152+
</standard>
153+
<code_comparison>
154+
<code title="Valid: Using a colon for case and default statements.">
155+
<![CDATA[
156+
switch ($foo) {
157+
case 'bar'<em>:</em>
158+
break;
159+
default<em>:</em>
160+
break;
161+
}
162+
]]>
163+
</code>
164+
<code title="Invalid: Using a semi-colon or colon followed by braces.">
165+
<![CDATA[
166+
switch ($foo) {
167+
case 'bar'<em>;</em>
168+
break;
169+
default: <em>{</em>
170+
break;
171+
<em>}</em>
172+
}
173+
]]>
174+
</code>
175+
</code_comparison>
176+
<standard>
177+
<![CDATA[
178+
There must be a comment when fall-through is intentional in a non-empty case body.
179+
]]>
180+
</standard>
83181
<code_comparison>
84-
<code title="Valid: Comment marking intentional fall-through.">
182+
<code title="Valid: Comment marking intentional fall-through in a non-empty case body.">
85183
<![CDATA[
86184
switch ($foo) {
87185
case 'bar':
88-
<em>// no break</em>
89-
default<em></em>:
186+
echo $foo;
187+
<em>// no break</em>
188+
default:
90189
break;
91190
}
92191
]]>
93192
</code>
94-
<code title="Invalid: No comment marking intentional fall-through.">
193+
<code title="Invalid: No comment marking intentional fall-through in a non-empty case body.">
95194
<![CDATA[
96195
switch ($foo) {
97196
case 'bar':
98-
default<em></em>:
197+
echo $foo;<em></em>
198+
default:
99199
break;
100200
}
101201
]]>

0 commit comments

Comments
 (0)