File tree Expand file tree Collapse file tree 1 file changed +101
-0
lines changed
src/Standards/PSR2/Docs/ControlStructures Expand file tree Collapse file tree 1 file changed +101
-0
lines changed Original file line number Diff line number Diff line change 1
1
<documentation title =" Switch Declaration" >
2
+ <standard >
3
+ <![CDATA[
4
+ Case and default keywords must be lowercase.
5
+ ]]>
6
+ </standard >
7
+ <code_comparison >
8
+ <code title =" Valid: Keywords in lowercase." >
9
+ <![CDATA[
10
+ switch ($foo) {
11
+ <em>case</em> 'bar':
12
+ break;
13
+ <em>default</em>:
14
+ break;
15
+ }
16
+ ]]>
17
+ </code >
18
+ <code title =" Invalid: Keywords not in lowercase." >
19
+ <![CDATA[
20
+ switch ($foo) {
21
+ <em>CASE</em> 'bar':
22
+ break;
23
+ <em>Default</em>:
24
+ break;
25
+ }
26
+ ]]>
27
+ </code >
28
+ </code_comparison >
2
29
<standard >
3
30
<![CDATA[
4
31
Case statements must be followed by exactly one space.
@@ -45,6 +72,52 @@ switch ($foo) {
45
72
break;
46
73
default<em> </em>:
47
74
break;
75
+ }
76
+ ]]>
77
+ </code >
78
+ </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>
48
121
}
49
122
]]>
50
123
</code >
@@ -68,6 +141,34 @@ switch ($foo) {
68
141
switch ($foo) {
69
142
case 'bar':
70
143
<em> </em>break;
144
+ }
145
+ ]]>
146
+ </code >
147
+ </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>
71
172
}
72
173
]]>
73
174
</code >
You can’t perform that action at this time.
0 commit comments