@@ -18,9 +18,9 @@ final class AttributesTest extends AbstractMethodUnitTest
18
18
/**
19
19
* Test that attributes are parsed correctly.
20
20
*
21
- * @param string $testMarker The comment which prefaces the target token in the test file.
22
- * @param int $length The number of tokens between opener and closer.
23
- * @param array $tokenCodes The codes of tokens inside the attributes.
21
+ * @param string $testMarker The comment which prefaces the target token in the test file.
22
+ * @param int $length The number of tokens between opener and closer.
23
+ * @param array<int|string> $tokenCodes The codes of tokens inside the attributes.
24
24
*
25
25
* @dataProvider dataAttribute
26
26
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -64,22 +64,22 @@ function ($token) use ($attribute, $length) {
64
64
*
65
65
* @see testAttribute()
66
66
*
67
- * @return array
67
+ * @return array<string, array<string, string|int|array<int|string>>>
68
68
*/
69
69
public static function dataAttribute ()
70
70
{
71
71
return [
72
- [
73
- '/* testAttribute */ ' ,
74
- 2 ,
75
- [
76
- T_STRING ,
72
+ ' class attribute ' => [
73
+ 'testMarker ' => ' /* testAttribute */ ' ,
74
+ ' length ' => 2 ,
75
+ ' tokenCodes ' => [
76
+ T_STRING
77
77
],
78
78
],
79
- [
80
- '/* testAttributeWithParams */ ' ,
81
- 7 ,
82
- [
79
+ ' class attribute with param ' => [
80
+ 'testMarker ' => ' /* testAttributeWithParams */ ' ,
81
+ ' length ' => 7 ,
82
+ ' tokenCodes ' => [
83
83
T_STRING ,
84
84
T_OPEN_PARENTHESIS ,
85
85
T_STRING ,
@@ -88,10 +88,10 @@ public static function dataAttribute()
88
88
T_CLOSE_PARENTHESIS ,
89
89
],
90
90
],
91
- [
92
- '/* testAttributeWithNamedParam */ ' ,
93
- 10 ,
94
- [
91
+ ' class attribute with named param ' => [
92
+ 'testMarker ' => ' /* testAttributeWithNamedParam */ ' ,
93
+ ' length ' => 10 ,
94
+ ' tokenCodes ' => [
95
95
T_STRING ,
96
96
T_OPEN_PARENTHESIS ,
97
97
T_PARAM_NAME ,
@@ -103,17 +103,17 @@ public static function dataAttribute()
103
103
T_CLOSE_PARENTHESIS ,
104
104
],
105
105
],
106
- [
107
- '/* testAttributeOnFunction */ ' ,
108
- 2 ,
109
- [
110
- T_STRING ,
106
+ ' function attribute ' => [
107
+ 'testMarker ' => ' /* testAttributeOnFunction */ ' ,
108
+ ' length ' => 2 ,
109
+ ' tokenCodes ' => [
110
+ T_STRING
111
111
],
112
112
],
113
- [
114
- '/* testAttributeOnFunctionWithParams */ ' ,
115
- 17 ,
116
- [
113
+ ' function attribute with params ' => [
114
+ 'testMarker ' => ' /* testAttributeOnFunctionWithParams */ ' ,
115
+ ' length ' => 17 ,
116
+ ' tokenCodes ' => [
117
117
T_STRING ,
118
118
T_OPEN_PARENTHESIS ,
119
119
T_CONSTANT_ENCAPSED_STRING ,
@@ -132,10 +132,10 @@ public static function dataAttribute()
132
132
T_CLOSE_PARENTHESIS ,
133
133
],
134
134
],
135
- [
136
- '/* testAttributeWithShortClosureParameter */ ' ,
137
- 17 ,
138
- [
135
+ ' function attribute with arrow function as param ' => [
136
+ 'testMarker ' => ' /* testAttributeWithShortClosureParameter */ ' ,
137
+ ' length ' => 17 ,
138
+ ' tokenCodes ' => [
139
139
T_STRING ,
140
140
T_OPEN_PARENTHESIS ,
141
141
T_STATIC ,
@@ -154,10 +154,10 @@ public static function dataAttribute()
154
154
T_CLOSE_PARENTHESIS ,
155
155
],
156
156
],
157
- [
158
- '/* testAttributeGrouping */ ' ,
159
- 26 ,
160
- [
157
+ ' function attribute; multiple comma separated classes ' => [
158
+ 'testMarker ' => ' /* testAttributeGrouping */ ' ,
159
+ ' length ' => 26 ,
160
+ ' tokenCodes ' => [
161
161
T_STRING ,
162
162
T_COMMA ,
163
163
T_WHITESPACE ,
@@ -185,10 +185,10 @@ public static function dataAttribute()
185
185
T_CLOSE_PARENTHESIS ,
186
186
],
187
187
],
188
- [
189
- '/* testAttributeMultiline */ ' ,
190
- 31 ,
191
- [
188
+ ' function attribute; multiple comma separated classes, one per line ' => [
189
+ 'testMarker ' => ' /* testAttributeMultiline */ ' ,
190
+ ' length ' => 31 ,
191
+ ' tokenCodes ' => [
192
192
T_WHITESPACE ,
193
193
T_WHITESPACE ,
194
194
T_STRING ,
@@ -221,10 +221,10 @@ public static function dataAttribute()
221
221
T_WHITESPACE ,
222
222
],
223
223
],
224
- [
225
- '/* testFqcnAttribute */ ' ,
226
- 13 ,
227
- [
224
+ ' function attribute; using partially qualified and fully qualified class names ' => [
225
+ 'testMarker ' => ' /* testFqcnAttribute */ ' ,
226
+ ' length ' => 13 ,
227
+ ' tokenCodes ' => [
228
228
T_STRING ,
229
229
T_NS_SEPARATOR ,
230
230
T_STRING ,
@@ -294,10 +294,10 @@ public function testAttributeAndLineComment()
294
294
/**
295
295
* Test that attributes on function declaration parameters are parsed correctly.
296
296
*
297
- * @param string $testMarker The comment which prefaces the target token in the test file.
298
- * @param int $position The token position (starting from T_FUNCTION) of T_ATTRIBUTE token.
299
- * @param int $length The number of tokens between opener and closer.
300
- * @param array $tokenCodes The codes of tokens inside the attributes.
297
+ * @param string $testMarker The comment which prefaces the target token in the test file.
298
+ * @param int $position The token position (starting from T_FUNCTION) of T_ATTRIBUTE token.
299
+ * @param int $length The number of tokens between opener and closer.
300
+ * @param array<int|string> $tokenCodes The codes of tokens inside the attributes.
301
301
*
302
302
* @dataProvider dataAttributeOnParameters
303
303
*
@@ -347,24 +347,24 @@ function ($token) use ($attribute, $length) {
347
347
*
348
348
* @see testAttributeOnParameters()
349
349
*
350
- * @return array
350
+ * @return array<string, array<string, string|int|array<int|string>>>
351
351
*/
352
352
public static function dataAttributeOnParameters ()
353
353
{
354
354
return [
355
- [
356
- '/* testSingleAttributeOnParameter */ ' ,
357
- 4 ,
358
- 2 ,
359
- [
360
- T_STRING ,
355
+ ' parameter attribute; single, inline ' => [
356
+ 'testMarker ' => ' /* testSingleAttributeOnParameter */ ' ,
357
+ ' position ' => 4 ,
358
+ ' length ' => 2 ,
359
+ ' tokenCodes ' => [
360
+ T_STRING
361
361
],
362
362
],
363
- [
364
- '/* testMultipleAttributesOnParameter */ ' ,
365
- 4 ,
366
- 10 ,
367
- [
363
+ ' parameter attribute; multiple comma separated, inline ' => [
364
+ 'testMarker ' => ' /* testMultipleAttributesOnParameter */ ' ,
365
+ ' position ' => 4 ,
366
+ ' length ' => 10 ,
367
+ ' tokenCodes ' => [
368
368
T_STRING ,
369
369
T_COMMA ,
370
370
T_WHITESPACE ,
@@ -376,11 +376,11 @@ public static function dataAttributeOnParameters()
376
376
T_CLOSE_PARENTHESIS ,
377
377
],
378
378
],
379
- [
380
- '/* testMultilineAttributesOnParameter */ ' ,
381
- 4 ,
382
- 13 ,
383
- [
379
+ ' parameter attribute; single, multiline ' => [
380
+ 'testMarker ' => ' /* testMultilineAttributesOnParameter */ ' ,
381
+ ' position ' => 4 ,
382
+ ' length ' => 13 ,
383
+ ' tokenCodes ' => [
384
384
T_WHITESPACE ,
385
385
T_WHITESPACE ,
386
386
T_STRING ,
@@ -403,10 +403,10 @@ public static function dataAttributeOnParameters()
403
403
/**
404
404
* Test that an attribute containing text which looks like a PHP close tag is tokenized correctly.
405
405
*
406
- * @param string $testMarker The comment which prefaces the target token in the test file.
407
- * @param int $length The number of tokens between opener and closer.
408
- * @param array $expectedTokensAttribute The codes of tokens inside the attributes.
409
- * @param array $expectedTokensAfter The codes of tokens after the attributes.
406
+ * @param string $testMarker The comment which prefaces the target token in the test file.
407
+ * @param int $length The number of tokens between opener and closer.
408
+ * @param array<array<string>> $expectedTokensAttribute The codes of tokens inside the attributes.
409
+ * @param array<int|string> $expectedTokensAfter The codes of tokens after the attributes.
410
410
*
411
411
* @covers PHP_CodeSniffer\Tokenizers\PHP::parsePhpAttribute
412
412
*
@@ -455,15 +455,15 @@ public function testAttributeContainingTextLookingLikeCloseTag($testMarker, $len
455
455
*
456
456
* @see dataAttributeOnTextLookingLikeCloseTag()
457
457
*
458
- * @return array
458
+ * @return array<string, array<string, string|int|array<array<string>>|array<int|string>>>
459
459
*/
460
460
public static function dataAttributeOnTextLookingLikeCloseTag ()
461
461
{
462
462
return [
463
- [
464
- '/* testAttributeContainingTextLookingLikeCloseTag */ ' ,
465
- 5 ,
466
- [
463
+ ' function attribute; string param with "?>" ' => [
464
+ 'testMarker ' => ' /* testAttributeContainingTextLookingLikeCloseTag */ ' ,
465
+ ' length ' => 5 ,
466
+ ' expectedTokensAttribute ' => [
467
467
[
468
468
'T_STRING ' ,
469
469
'DeprecationReason ' ,
@@ -485,7 +485,7 @@ public static function dataAttributeOnTextLookingLikeCloseTag()
485
485
'] ' ,
486
486
],
487
487
],
488
- [
488
+ ' expectedTokensAfter ' => [
489
489
T_WHITESPACE ,
490
490
T_FUNCTION ,
491
491
T_WHITESPACE ,
@@ -497,10 +497,10 @@ public static function dataAttributeOnTextLookingLikeCloseTag()
497
497
T_CLOSE_CURLY_BRACKET ,
498
498
],
499
499
],
500
- [
501
- '/* testAttributeContainingMultilineTextLookingLikeCloseTag */ ' ,
502
- 8 ,
503
- [
500
+ ' function attribute; string param with "?>"; multiline ' => [
501
+ 'testMarker ' => ' /* testAttributeContainingMultilineTextLookingLikeCloseTag */ ' ,
502
+ ' length ' => 8 ,
503
+ ' expectedTokensAttribute ' => [
504
504
[
505
505
'T_STRING ' ,
506
506
'DeprecationReason ' ,
@@ -534,7 +534,7 @@ public static function dataAttributeOnTextLookingLikeCloseTag()
534
534
'] ' ,
535
535
],
536
536
],
537
- [
537
+ ' expectedTokensAfter ' => [
538
538
T_WHITESPACE ,
539
539
T_FUNCTION ,
540
540
T_WHITESPACE ,
0 commit comments