-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdocumentation.html
More file actions
303 lines (294 loc) · 25 KB
/
documentation.html
File metadata and controls
303 lines (294 loc) · 25 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<html>
<head>
<title>TYPO3SniffPool Coding Standards</title>
<style>
body {
background-color: #FFFFFF;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #000000;
}
h1 {
color: #666666;
font-size: 20px;
font-weight: bold;
margin-top: 0px;
background-color: #E6E7E8;
padding: 20px;
border: 1px solid #BBBBBB;
}
h2 {
color: #00A5E3;
font-size: 16px;
font-weight: normal;
margin-top: 50px;
}
.code-comparison {
width: 100%;
}
.code-comparison td {
border: 1px solid #CCCCCC;
}
.code-comparison-title, .code-comparison-code {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
vertical-align: top;
padding: 4px;
width: 50%;
background-color: #F1F1F1;
line-height: 15px;
}
.code-comparison-code {
font-family: Courier;
background-color: #F9F9F9;
}
.code-comparison-highlight {
background-color: #DDF1F7;
border: 1px solid #00A5E3;
line-height: 15px;
}
.tag-line {
text-align: center;
width: 100%;
margin-top: 30px;
font-size: 12px;
}
.tag-line a {
color: #000000;
}
</style>
</head>
<body>
<h1>TYPO3SniffPool Coding Standards</h1>
<h2>Table of Contents</h2>
<ul class="toc">
<li><a href="#Switch-Declaration">Switch Declaration</a></li>
<li><a href="#Ternary-Conditional-Operator">Ternary Conditional Operator</a></li>
<li><a href="#ConcatenationSpacing">ConcatenationSpacing</a></li>
<li><a href="#Closing-Brace-Indentation">Closing Brace Indentation</a></li>
</ul>
<a name="Switch-Declaration" />
<h2>Switch Declaration</h2>
<p class="text">This standard covers all switch declarations.</p>
<p class="text">The keywords <em>Switch</em>, <em>Case</em> and <em>Default</em> should be lowercase</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Lowercase keywords</td>
<td class="code-comparison-title">Invalid: Keywords begins with a uppercase letter or are complete uppercase</td>
</tr>
<tr>
<td class="code-comparison-code"><span class="code-comparison-highlight">switch</span> ($something) {</br> <span class="code-comparison-highlight">case</span> '1':</br> $case = '1';</br> break;</br> <span class="code-comparison-highlight">case</span> '2':</br> $case = '3';</br> break;</br> <span class="code-comparison-highlight">default:</span></br> $case = null;</br>}</td>
<td class="code-comparison-code"><span class="code-comparison-highlight">Switch</span> ($something) {</br> <span class="code-comparison-highlight">CASE</span> '1':</br> $case = '1';</br> break;</br> <span class="code-comparison-highlight">CASE</span> '2':</br> $case = '3';</br> break;</br> <span class="code-comparison-highlight">Default:</span></br> $case = null;</br>}</td>
</tr>
</table>
<p class="text"><em>Case</em> and <em>Default</em> statements are indented with a single indent (tab) inside the <em>Switch</em> statement.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Case statement is indent with one tab</td>
<td class="code-comparison-title">Invalid: Case statement is indent with one space. Case statement is not indent at all or with two tabs.</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br>...</br>}</td>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight">[space]</span>case '1':</br>...</br>}</br></br>switch ($something) {</br><span class="code-comparison-highlight"></span>case '1':</br>...</br>}</br></br>switch ($something) {</br><span class="code-comparison-highlight">[tab][tab]</span>case '1':</br>...</br>}</td>
</tr>
</table>
<p class="text"><em>Case</em> keyword should be followed by a single space.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Case statement is followed by a single space</td>
<td class="code-comparison-title">Invalid: No space after Case statement</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case<span class="code-comparison-highlight"> </span>'1':</br>...</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case<span class="code-comparison-highlight"></span>'1':</br>...</br>}</td>
</tr>
</table>
<p class="text">There should be no space before the colon.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: No space before the colon</td>
<td class="code-comparison-title">Invalid: Space before the colon</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1'<span class="code-comparison-highlight"></span>:</br>...</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1'<span class="code-comparison-highlight"> </span>:</br>...</br>}</td>
</tr>
</table>
<p class="text">If one <em>Case</em> block has to pass control into another <em>Case</em> block without having a <em>Break</em>, there must be a comment about it in the code.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: The fall-through is explained with a comment</td>
<td class="code-comparison-title">Invalid: No comment at the fall-through</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> case '2':</br> $case = '3';</br> <span class="code-comparison-highlight">// Fall through the next case on purpose</span></br> case '3':</br> $case = '3';</br> break;</br> default:</br> $case = null;</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> case '2':</br> $case = '3';</br> <span class="code-comparison-highlight"></span></br> case '3':</br> $case = '3';</br> break;</br> default:</br> $case = null;</br>}</td>
</tr>
</table>
<p class="text">The <em>Default</em> statement must be the last in the <em>Switch</em> and must not have a <em>Break</em> statement.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: The default statement is the last in the switch and have no break statement.</td>
<td class="code-comparison-title">Invalid: Default statement is not the last element and it contains a break.</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> default:</br> $case = null;</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> <span class="code-comparison-highlight">default:</br> $case = null;</span></br> case '2':</br> $case = '2';</br> break;</br>}</br></br>switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> default:</br> $case = null;</br> <span class="code-comparison-highlight">break;</span></br>}</td>
</tr>
</table>
<p class="text">The code inside the <em>Case</em> statements is further indented with a single (tab) indent.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: The code is indent one more tab then case statement.</td>
<td class="code-comparison-title">Invalid: The code is indent with spaces or with only one tab.</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[tab][tab]</span>$case = '1';</br>...</br>}</td>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[space][space]</span>$case = '1';</br>...</br>}</br></br>switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[tab]</span>$case = '1';</br>...</br>}</br></br>switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[tab][tab][tab]</span>$case = '1';</br>...</br>}</td>
</tr>
</table>
<p class="text">The <em>Break</em> statement is aligned with the code.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: The break statement is aligned to the code.</td>
<td class="code-comparison-title">Invalid: The break statement is not aligned with the code.</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[tab][tab]</span>$case = '1';</br><span class="code-comparison-highlight">[tab][tab]</span>break;</br>...</br>}</td>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[tab][tab]</span>$case = '1';</br><span class="code-comparison-highlight">[tab]</span>break;</br>...</br>}</br></br>switch ($something) {</br><span class="code-comparison-highlight">[tab]</span>case '1':</br><span class="code-comparison-highlight">[tab][tab]</span>$case = '1';</br><span class="code-comparison-highlight">[tab][tab][tab]</span>break;</br>...</br>}</td>
</tr>
</table>
<p class="text">There should be no blank lines before the <em>Break</em> statement</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: No blank line before the break statement</td>
<td class="code-comparison-title">Invalid: Blank line before the break statement</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';<span class="code-comparison-highlight"></span></br> break;</br> default:</br> $case = null;</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br><span class="code-comparison-highlight"> </span></br> break;</br> default:</br> $case = null;</br>}</td>
</tr>
</table>
<p class="text">Only one <em>Break</em> statement is allowed per <em>Case</em>.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Only one break statement per case</td>
<td class="code-comparison-title">Invalid: Two case statements per case</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> <span class="code-comparison-highlight">break;</span></br>...</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> <span class="code-comparison-highlight">break;</br> break;</span></br>...</br>}</td>
</tr>
</table>
<p class="text">There should be no blank lines after the <em>Case</em> statement</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: No blank line after the case statement</td>
<td class="code-comparison-title">Invalid: Blank line after the case statement</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':<span class="code-comparison-highlight"></span></br> $case = '1';</br> break;</br> default:</br> $case = null;</br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br><span class="code-comparison-highlight"> </span></br> $case = '1';</br> break;</br> default:</br> $case = null;</br>}</td>
</tr>
</table>
<p class="text">All <em>Switch</em> statements must contain a <em>Default</em> case</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Switch with a default case</td>
<td class="code-comparison-title">Invalid: Switch without a default case</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> <span class="code-comparison-highlight">default:</br> $case = null;</br></span></br>}</td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br><span class="code-comparison-highlight"></span></br>}</td>
</tr>
</table>
<p class="text">Closing brace of the <em>Switch</em> statement must aligned with the <em>Switch</em> keyword</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Closing brace aligned with the switch keyword</td>
<td class="code-comparison-title">Invalid: Closing brace not aligned with the switch keyword</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> default:</br> $case = null;</br><span class="code-comparison-highlight">}</span></td>
<td class="code-comparison-code">switch ($something) {</br> case '1':</br> $case = '1';</br> break;</br> default:</br> $case = null;</br><span class="code-comparison-highlight"> }</span></td>
</tr>
</table>
<p class="text"><em>Switch</em> statement must contain at least one <em>Case</em> statement</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Switch contains at least one case statement</td>
<td class="code-comparison-title">Invalid: Switch contains not case statement</td>
</tr>
<tr>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight"> case '1':</br> $case = '1';</br> break;</span></br> default:</br> $case = null;</br>}</br></br>switch ($something) {</br><span class="code-comparison-highlight"> default:</br> $case = null;</span></br>}</td>
<td class="code-comparison-code">switch ($something) {</br><span class="code-comparison-highlight"></span></br>}</td>
</tr>
</table>
<a name="Ternary-Conditional-Operator" />
<h2>Ternary Conditional Operator</h2>
<p class="text">This checks the correct usage of ternary conditional operators</p>
<p class="text">The ternary conditional operator ? : must be used only, if it has exactly two outcomes.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: The ternary conditional operator is not nested.</td>
<td class="code-comparison-title">Invalid: The ternary conditional operator is nested.</td>
</tr>
<tr>
<td class="code-comparison-code">$result = ($useComma ? ',' : '.');</td>
<td class="code-comparison-code">$result = ($useComma ? ',' : <span class="code-comparison-highlight">$useDot ? '.' : ';'</span>);</td>
</tr>
</table>
<a name="ConcatenationSpacing" />
<h2>ConcatenationSpacing</h2>
<p class="text">This standard is about the spacing of concat strings</p>
<p class="text"><em>String concatenation</em> operators must be surrounded by spaces</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: String concatenation operator surrounded by space</td>
<td class="code-comparison-title">Invalid: String concatenation operator is not surrounded by space</td>
</tr>
<tr>
<td class="code-comparison-code">$content = 'Hello '<span class="code-comparison-highlight"> </span>.<span class="code-comparison-highlight"> </span>'world!';</td>
<td class="code-comparison-code">$content = 'Hello '<span class="code-comparison-highlight"></span>.<span class="code-comparison-highlight"> </span>'world!';</br></br>$content = 'Hello '<span class="code-comparison-highlight"> </span>.<span class="code-comparison-highlight"></span>'world!';</br></br>$content = 'Hello '<span class="code-comparison-highlight"></span>.<span class="code-comparison-highlight"></span>'world!';</td>
</tr>
</table>
<p class="text"><em>String concatenation</em> operators should be surrounded by only one space</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: String concatenation operator surrounded by one space on every side</td>
<td class="code-comparison-title">Invalid: String concatenation operator surrounded by multiple spaces</td>
</tr>
<tr>
<td class="code-comparison-code">$content = 'Hello '<span class="code-comparison-highlight"> </span>.<span class="code-comparison-highlight"> </span>'world!';</td>
<td class="code-comparison-code">$content = 'Hello '<span class="code-comparison-highlight"> </span>.<span class="code-comparison-highlight"> </span>'world!';</br></br>$content = 'Hello '<span class="code-comparison-highlight"> </span>.<span class="code-comparison-highlight"> </span>'world!';</td>
</tr>
</table>
<a name="Closing-Brace-Indentation" />
<h2>Closing Brace Indentation</h2>
<p class="text">This checks the indention of the closing brace of a scope</p>
<p class="text">The closing curly brace must start on a new line.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: The closing curly brace starts on a new line.</td>
<td class="code-comparison-title">Invalid: The closing curly brace doesn't starts on a new line.</td>
</tr>
<tr>
<td class="code-comparison-code">if ($test) {</br> $var = 1;</br><span class="code-comparison-highlight">}</span></br></br>function test2() {</br><span class="code-comparison-highlight">}</span></td>
<td class="code-comparison-code">if ($test) {</br> $var = 1;<span class="code-comparison-highlight">}</span></br></br>function test2() {<span class="code-comparison-highlight">}</span></td>
</tr>
</table>
<p class="text">Closing braces should be indented at the same level as the beginning of the scope.</p>
<table class="code-comparison">
<tr>
<td class="code-comparison-title">Valid: Consistent indentation level for scope.</td>
<td class="code-comparison-title">Invalid: The ending brace is indented further than the if statement.</td>
</tr>
<tr>
<td class="code-comparison-code">if ($test) {</br> $var = 1;</br>}</td>
<td class="code-comparison-code">if ($test) {</br> $var = 1;</br><span class="code-comparison-highlight"> </span>}</td>
</tr>
</table>
<div class="tag-line">Documentation generated on Mon, 04 Nov 2013 18:48:15 +0100 by <a href="http://pear.php.net/package/PHP_CodeSniffer">PHP_CodeSniffer 1.4.6</a></div>
</body>
</html>