forked from PHPCheckstyle/phpcheckstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.anorak.yml
495 lines (438 loc) · 10.1 KB
/
.anorak.yml
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
specialFunctions:
- "__construct"
- "__destruct"
- "__call"
- "__get"
- "__set"
- "__isset"
- "__unset"
- "__sleep"
- "__wakeup"
- "__toString"
- "__set_state"
- "__clone"
- "__autoload"
- "__invoke"
- "__callStatic"
systemVariables:
- "$this"
- "$_GET"
- "$_POST"
- "$_FILES"
- "$_COOKIE"
- "$_SESSION"
- "$_ENV"
- "$_SERVER"
- "$_REQUEST"
- "$HTTP_GET_VARS"
- "$HTTP_POST_VARS"
- "$HTTP_COOKIE_VARS"
- "$HTTP_SERVER_VARS"
- "$HTTP_ENV_VARS"
- "$HTTP_SESSION_VARS"
# Constant naming
constantNaming:
regexp: "/^[A-Z][A-Z0-9_]*$/"
level: "error"
# Default naming
variableNaming:
regexp: "/^[a-z_][a-zA-Z0-9]*$/"
# Top Level Variables
topLevelVariableNaming:
regexp: "/^[a-z_][a-zA-Z0-9]*$/"
# Local variables (inside a class)
localVariableNaming:
regexp: "/^[a-z_][a-zA-Z0-9]*$/"
# Member variables (inside a function)
memberVariableNaming:
regexp: "/^[a-z_][a-zA-Z0-9]*$/"
# Function naming
functionNaming:
regexp: "/^[a-z_][a-zA-Z0-9]*$/"
# Protected Function naming
protectedFunctionNaming:
level: "error"
regexp: "/^_[a-z][a-zA-Z0-9]*$/"
# Private Function naming
privateFunctionNaming:
level: "error"
regexp: "/^_[a-z][a-zA-Z0-9]*$/"
# Constructor naming
constructorNaming:
naming: "new"
# Class naming
classNaming:
level: "error"
regexp: "/^[A-Z][a-zA-Z0-9_]*$/"
# Interface naming
interfaceNaming:
level: "error"
regexp: "/^[A-Z][a-zA-Z0-9_]*$/"
# File naming
fileNaming:
level: "error"
regexp: "/^[a-zA-Z][a-zA-Z0-9._]*$/"
# Short variable names
localScopeVariableLength:
minLength: 2
maxLength: 30
exception:
- "i"
- "j"
- "k"
- "e"
# Test if a short php code open tag is used (<? instead of <?php )
noShortPhpCodeTag:
# Test if a PHP closing file is present at the end of the file
noFileCloseTag:
# Test if a file finish with some inner HTML.
noFileFinishHTML:
level: "error"
# Prevent C Style comments from being used
noShellComments:
# Doc Blocks MUST be used
docBlocks:
excludePrivateMembers: true
testReturn: true
testParam: true
testThrow: true
# Indentation
indentation:
type: "tabs"
number: 4
# Check the position of the open curly brace in a control structure (if)
# sl = same line
# nl = new line
controlStructOpenCurly:
position: "sl"
# Check the position of the close curly brace
controlCloseCurly:
level: "info"
# Check the position of the open curly brace after a function
funcDefintionOpenCurly:
position: "sl"
# Check the position of the else
controlStructElse:
position: "sl"
# Tests that control statements are followed by a space BEFORE the opening paren
spaceAfterControlStmt:
# Check that there is no space after a function name in a function call
noSpaceAfterFunctionName:
level: "info"
# Check for the required presence of a white space after some tokens
checkWhiteSpaceAfter:
# Check for the required presence of a white space before some tokens
checkWhiteSpaceBefore:
exception:
- ":" # Because of the switch/case
# Check that there is no space before some tokens : "!" "(" "->" -->
noSpaceBeforeToken:
level: "info"
# Check that there is no space after some tokens : "!" "(" "->" -->
noSpaceAfterToken:
level: "info"
# Check that the length of the line doesn't pass the max value
lineLength:
level: "info"
maxLineLength: 120
checkHTMLLines: false
# Function length
functionLength:
level: "info"
maxLength: 200
# Function Max Parameters
functionMaxParameters:
maxParameters: 4
# Check Cyclomatic Complexity
cyclomaticComplexity:
warningLevel: 10
errorLevel: 20
# Prohibited functions
checkProhibitedFunctions:
item:
- "echo"
- "system"
- "print_r"
- "var_dump"
- "dl"
- "define_syslog_variables"
- "set_magic_quotes_runtime"
- "magic_quotes_runtime"
- "sql_regcase"
- "exec"
- "passthru"
- "delete"
- "unlink"
- "phpinfo"
- "die"
# - "copy"
# - "fwrite"
# Prohibited tokens
checkProhibitedTokens:
item:
- "T_BAD_CHARACTER"
- "T_DECLARE"
- "T_ENDDECLARE"
- "T_ENDFOR"
- "T_ENDFOREACH"
- "T_ENDIF"
- "T_ENDSWITCH"
- "T_ENDWHILE"
- "T_HALT_COMPILER"
- "T_OLD_FUNCTION"
- "T_PRINT"
# - "T_OPEN_TAG_WITH_ECHO"
# - "T_INLINE_HTML"
# - "T_ECHO"
# All arguments with default values should be at the end
defaultValuesOrder:
# Check for silenced errors before function calls (@function)
checkSilencedError:
exception:
- "rename"
- "mkdir"
- "chmod"
# Avoid passing parameters by reference
avoidPassingReferences:
showTODOs:
# Use boolean operators (&&) instead of logical operators (AND)
useBooleanOperators:
# Check empty block like if ($) {}
checkEmptyBlock:
#exception:
# catch
# Check empty statement (;;)
checkEmptyStatement:
# Check for the presence of heredoc
checkHeredoc:
# Check for braces around code blocks (if, else, elseif, do, while, for, foreach)
needBraces:
# Switch need a default value
switchNeedDefault:
# Switch default value should be at the end
switchDefaultOrder:
# Avoid using unary operators (++) inside a control statement
# with the exception of for iterators.
checkUnaryOperator:
exception:
- "for"
# With inner assignments it's difficult to see all places where a variable is set_magic_quotes_runtime
checkInnerAssignment:
exception:
- "for"
# Only one class declaration per PHP file
oneClassPerFile:
# Detect unused private functions
checkUnusedPrivateFunctions:
# Detect unused code
checkUnusedCode:
# Detect empty files
checkEmptyFile:
# Avoid using count/sizeof functions inside a loop
functionInsideLoop:
# Replace deprecated methods
checkDeprecation:
"call_user_method":
old: "call_user_method"
new: "call_user_func"
version: "4.1"
"call_user_method_array":
old: "call_user_method_array"
new: "call_user_func_array"
version: "4.1"
"define_syslog_variables":
old: "define_syslog_variables"
new: "none"
version: "5.4"
"dl":
old: "dl"
new: "extension_loaded"
version: "5.3"
"ereg":
old: "ereg"
new: "preg_match('@'.$pattern.'@', $string)"
version: "5.3"
"eregi":
old: "eregi"
new: "preg_match('@'.$pattern.'@i', $string)"
version: "5.3"
"ereg_replace":
old: "ereg_replace"
new: "preg_replace('@'.$pattern.'@', $string)"
version: "5.3"
"eregi_replace":
old: "eregi_replace"
new: "preg_replace('@'.$pattern.'@i', $string)"
version: "5.3"
"import_request_variables":
old: "import_request_variables"
new: "none"
version: "5.4"
"magic_quotes_runtime":
old: "magic_quotes_runtime"
new: "none"
version: "5.3"
"set_magic_quotes_runtime":
old: "set_magic_quotes_runtime"
new: "none"
version: "5.3"
"mcrypt_generic_end":
old: "mcrypt_generic_end"
new: "mcrypt_generic_deinit"
version: "5.4"
"mysql_list_dbs":
old: "mysql_list_dbs"
new: "none"
version: "5.4"
"mysql_db_query":
old: "mysql_db_query"
new: "mysql_select_db and mysql_query"
version: "5.3"
"mysql_escape_string":
old: "mysql_escape_string"
new: "mysql_real_escape_string"
version: "5.3"
"mysqli_bind_param":
old: "mysqli_bind_param"
new: "mysqli_stmt_bind_param"
version: "5.4"
"mysqli_bind_result":
old: "mysqli_bind_result"
new: "mysqli_stmt_bind_result"
version: "5.4"
"mysqli_client_encoding":
old: "mysqli_client_encoding"
new: "mysqli_character_set_name"
version: "5.4"
"mysqli_fetch":
old: "mysqli_fetch"
new: "mysqli_stmt_fetch"
version: "5.4"
"mysqli_param_count":
old: "mysqli_param_count"
new: "mysqli_stmt_param_count"
version: "5.4"
"mysqli_get_metadata":
old: "mysqli_get_metadata"
new: "mysqli_stmt_result_metadata"
version: "5.4"
"mysqli_send_long_data":
old: "mysqli_send_long_data"
new: " mysqli_stmt_send_long_data"
version: "5.4"
"session_register":
old: "session_register"
new: "$_SESSION"
version: "5.3"
"session_unregister":
old: "session_unregister"
new: "$_SESSION"
version: "5.3"
"session_is_registered":
old: "session_is_registered"
new: "$_SESSION"
version: "5.3"
"set_socket_blocking":
old: "set_socket_blocking"
new: "stream_set_blocking"
version: "5.3"
"split":
old: "split"
new: "explode($pattern, $string) or preg_split('@'.$pattern.'@', $string)"
version: "5.3"
"spliti":
old: "spliti"
new: "preg_split('@'.$pattern.'@i', $string)"
version: "5.3"
"sql_regcase":
old: "sql_regcase"
new: "none"
version: "5.3"
"$HTTP_GET_VARS":
old: "$HTTP_GET_VARS"
new: "$_GET"
version: "5.3"
"$HTTP_POST_VARS":
old: "$HTTP_POST_VARS"
new: "$_POST"
version: "5.3"
"$HTTP_COOKIE_VARS":
old: "$HTTP_COOKIE_VARS"
new: "$_COOKIE"
version: "5.3"
"$HTTP_SERVER_VARS":
old: "$HTTP_SERVER_VARS"
new: "$_SERVER"
version: "5.3"
"$HTTP_ENV_VARS":
old: "$HTTP_ENV_VARS"
new: "$_ENV"
version: "5.3"
"$HTTP_SESSION_VARS":
old: "$HTTP_SESSION_VARS"
new: "$_SESSION"
version: "5.3"
# Use only strict comparison
strictCompare:
# Replace deprecated methods
checkAliases:
"chop":
old: "chop"
new: "rtrim()"
"close":
old: "close"
new: "closedir()"
"die":
old: "die"
new: "exit()"
"dir":
old: "dir"
new: "getdir()"
"doubleval":
old: "doubleval"
new: "floatval()"
"fputs":
old: "fputs"
new: "fwrite()"
"ini_alter":
old: "ini_alter"
new: "ini_set()"
"is_double":
old: "is_double"
new: "is_float()"
"is_integer":
old: "is_integer"
new: "is_int()"
"is_long":
old: "is_long"
new: "is_int()"
"is_real":
old: "is_real"
new: "is_float()"
"is_writeable":
old: "is_writeable"
new: "is_writable()"
"join":
old: "join"
new: "implode()"
"key_exists":
old: "key_exists"
new: "array_key_exists()"
"magic_quotes_runtime":
old: "magic_quotes_runtime"
new: "set_magic_quotes_runtime()"
"pos":
old: "pos"
new: "current()"
"rewind":
old: "rewind"
new: "rewinddir()"
"show_source":
old: "show_source"
new: "highlight_file()"
"sizeof":
old: "sizeof"
new: "count()"
"strchr":
old: "strchr"
new: "strstr()"