forked from pfrenssen/coder
/
FunctionCommentUnitTest.inc
443 lines (375 loc) · 7.73 KB
/
FunctionCommentUnitTest.inc
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
<?php
/**
* @file
* Some function comment tests.
*/
/**
* Test.
*
* @param string $x
* Comment does not end with full stop
* @param string $y
* comment does not start with a capital letter.
*/
function foo($x, $y) {
}
/**
* Missing exception description in the throws tag, which is OK.
*
* @throws \Drupal\locale\StringStorageException
*/
function test1() {
}
/**
* Wrong indentation of description for the throws tag.
*
* @throws \Drupal\locale\StringStorageException
* Description here.
*/
function test2() {
}
/**
* Description for the throws tag does not start with capital letter.
*
* @throws \Drupal\locale\StringStorageException
* description here.
*/
function test3() {
}
/**
* Description for the throws tag does not end with a dot.
*
* @throws \Drupal\locale\StringStorageException
* Description here
*/
function test4() {
}
/**
* Description for the throws tag must be on the next line.
*
* @throws \Drupal\locale\StringStorageException Description here.
*/
function test5() {
}
/**
* Some description.
*
* @param string $foo
* Some parameter that does not exist.
*/
function test6() {
}
function test7() {
// Missing function doc here.
}
/**
* Test methods.
*/
class Test {
public function undocumented() {
}
// This should be a doc comment.
public function wrong() {
}
}
/**
* Some comment.
*
* @param int $x Description should be on the next line.
*/
function test8($x) {
}
/**
* Default implementation of a menu item (without a page or form controller).
*
* UML:
* @link http://drupal7demo.webel.com.au/node/1017 DefaultMenuItem @endlink.
*
* @param integer $foo
* Test.
*/
function test9($foo) {
}
/**
* Default implementation of a menu item (without a page or form controller).
*
* UML:
* @link http://drupal7demo.webel.com.au/node/1017 DefaultMenuItem @endlink.
*
* @param integer $foo Test.
*/
function test10($foo) {
}
/**
* A function may throw multiple exceptions.
*
* @throws \Exception
* Thrown when something bad happens.
* @throws \InvalidArgumentException
* Thrown when an argument is invalid.
*/
function test11() {
}
/**
* Update or set users expiration time
*
* @param object $user
* @param int $timespan (seconds)
*/
function test12($user, $timespan) {
}
/**
* Update or set users expiration time.
*
* @param object $user
* Object type hint in comment without real type hint is allowed.
*/
function test13($user) {
}
/**
* Update or set users expiration time.
*
* @param object $user
* Object stdClass type hint is allowed for object.
*/
function test14(stdClass $user) {
}
/**
* Array parameter type mismatch.
*
* @param array $foo
* Comment here.
*/
function test15(Test $foo) {
}
/*
* This should be converted into a doc comment.
*/
function test16() {
}
/**
* Return comment indentation should be three spaces.
*
* @return string
* This is not indented correctly.
*/
function test17() {
return '1';
}
/**
* Return comment indentation should be three spaces.
*
* @return string
*This is not indented correctly.
*/
function test18() {
return '1';
}
/**
* Return comment indentation should be three spaces.
*
* @return string
* This is not indented correctly. Continues on the next line because this is a
* really long sentence.
*/
function test19() {
return '1';
}
/**
* Multiple errors in @param line.
*
* @param string $arg1 This should be in next line and needs period
*/
function test20($arg1) {
}
/**
* Testing fix of incorrect param types.
*
* @param Array $arg1
* The parameter type is not valid.
* @param integer|bool $arg2
* One of the parameter types listed is not valid.
* @param integer|boolean|Array $arg3
* All of the parameter types listed are not valid.
*/
function test21($arg1, $arg2, $arg3) {
}
/**
* Test for allowed param var types.
*
* @param array|bool|float|int|mixed|object|string|resource|callable $arg1
* All of the above types are valid.
* @param Array|boolean|integer|str|stdClass|NULL $arg2
* All of the above types are invalid.
* @param array()|Boolean|number|String $arg3
* All of the above types are invalid.
* @param type $arg4
* All of the above types are invalid.
* @param FALSE|TRUE|Int $arg5
* All of the above types are invalid.
* @param Bool|Integer $arg6
* All of the above types are invalid.
*/
function test22($arg1, $arg2, $arg3, $arg4, $arg5, $arg6) {
}
/**
* Void returns allowed when null is given in @return.
*
* When null is a potential return value it should be allowed to have return
* statements with void return as well.
*
* @return bool|null
* This implies that the return value can be NULL, a boolean, or empty.
*/
function test23() {
if (1 == 2) {
return;
}
return TRUE;
}
/**
* Even when null is given in @return there must be at least 1 valid return.
*
* When null is a potential return value it should be allowed to have return
* statements with void return. This does not mean that all returns can be void.
* There must be at least one non-void return.
*
* @return bool|null
* This implies that the return value can be NULL, a boolean, or empty.
*/
function test24() {
if (1 == 2) {
return;
}
return;
}
/**
* The shorthand array syntax should not be used as a return type.
*
* @return []
* The array.
*/
function test25() {
return [];
}
/**
* Type declarations should not have any illegal characters.
*
* @param \Ille*al $var
* This asterisk does not belong here.
*
* @return \Some/Namespace
* This should not have a forward slash.
*/
function test26($var) {
return '';
}
/**
* Data types with spaces.
*
* @param string or int $x
* Data types should not contain spaces.
*
* @return int or bool
* Same spaces in data type here.
*/
function test27($x) {
return 0;
}
/**
* Return docs should not contain variable names.
*
* @return string $profile
* The profile.
*/
function test28() {
$profile = 'x';
return $profile;
}
/**
* Not fixable return comment.
*
* @return string $profile more confusing text here.
* The profile.
*/
function test29() {
$profile = 'x';
return $profile;
}
/**
* Indentation of param comment is wrong.
*
* @param string $xml_response
* String returned from CreateClientProfile.
*
* @return mixed
* Return fetched bookings or log error.
*/
function test30($xml_response) {
}
/**
* Class Test.
*/
class Test2 extends AbstractTest {
/**
* Run method with missing described variable.
*
* @param \stdClass $start
* Start point.
*
* @return bool
* Result.
*/
public function run(\stdClass $start, \stdClass $stop) {
return TRUE;
}
}
/**
* Comment of param is just one word, which means it is the data type.
*
* @param $a array
* @param $b array
*/
function test31($a, $b) {
}
class PostcodeAnywhere_Interactive_Find {
private $UserName; //The username associated with the Royal Mail license (not required for click licenses).
private $Data; //Holds the results of the query
function PostcodeAnywhere_Interactive_Find($Key, $SearchTerm, $PreferredLanguage, $Filter, $UserName)
{
$this->Key = $Key;
$this->SearchTerm = $SearchTerm;
$this->PreferredLanguage = $PreferredLanguage;
$this->Filter = $Filter;
$this->UserName = $UserName;
}
}
/**
* There should be no dots.
*
* @param string $a.
* Some comment.
* @param string $b.
* Another comment.
*/
function test32($a, $b) {
}
/**
* There should be no dots and comments should be on the next line.
*
* @param string $a. Some comment.
* @param string $b. Another comment.
*/
function test33($a, $b) {
}
/**
* Yield should be a recognised return statement.
*
* @return int
* Integer value.
*/
function test34($a, $b) {
for ($i = 1; $i <= 3; $i++) {
yield $i;
}
}