@@ -20,8 +20,8 @@ final class NamedFunctionCallArgumentsTest extends AbstractMethodUnitTest
20
20
* Verify that parameter labels are tokenized as T_PARAM_NAME and that
21
21
* the colon after it is tokenized as a T_COLON.
22
22
*
23
- * @param string $testMarker The comment prefacing the target token.
24
- * @param array $parameters The token content for each parameter label to look for.
23
+ * @param string $testMarker The comment prefacing the target token.
24
+ * @param array<string> $parameters The token content for each parameter label to look for.
25
25
*
26
26
* @dataProvider dataNamedFunctionCallArguments
27
27
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -74,206 +74,206 @@ public function testNamedFunctionCallArguments($testMarker, $parameters)
74
74
*
75
75
* @see testNamedFunctionCallArguments()
76
76
*
77
- * @return array
77
+ * @return array<string, array<string, string|array<string>>>
78
78
*/
79
79
public static function dataNamedFunctionCallArguments ()
80
80
{
81
81
return [
82
- [
83
- '/* testNamedArgs */ ' ,
84
- [
82
+ ' function call, single line, all named args ' => [
83
+ 'testMarker ' => ' /* testNamedArgs */ ' ,
84
+ ' parameters ' => [
85
85
'start_index ' ,
86
86
'count ' ,
87
87
'value ' ,
88
88
],
89
89
],
90
- [
91
- '/* testNamedArgsMultiline */ ' ,
92
- [
90
+ ' function call, multi-line, all named args ' => [
91
+ 'testMarker ' => ' /* testNamedArgsMultiline */ ' ,
92
+ ' parameters ' => [
93
93
'start_index ' ,
94
94
'count ' ,
95
95
'value ' ,
96
96
],
97
97
],
98
- [
99
- '/* testNamedArgsWithWhitespaceAndComments */ ' ,
100
- [
98
+ ' function call, single line, all named args; comments and whitespace ' => [
99
+ 'testMarker ' => ' /* testNamedArgsWithWhitespaceAndComments */ ' ,
100
+ ' parameters ' => [
101
101
'start_index ' ,
102
102
'count ' ,
103
103
'value ' ,
104
104
],
105
105
],
106
- [
107
- '/* testMixedPositionalAndNamedArgs */ ' ,
108
- [
106
+ ' function call, single line, mixed positional and named args ' => [
107
+ 'testMarker ' => ' /* testMixedPositionalAndNamedArgs */ ' ,
108
+ ' parameters ' => [
109
109
'double_encode ' ,
110
110
],
111
111
],
112
- [
113
- '/* testNestedFunctionCallOuter */ ' ,
114
- [
112
+ ' function call containing nested function call values ' => [
113
+ 'testMarker ' => ' /* testNestedFunctionCallOuter */ ' ,
114
+ ' parameters ' => [
115
115
'start_index ' ,
116
116
'count ' ,
117
117
'value ' ,
118
118
],
119
119
],
120
- [
121
- '/* testNestedFunctionCallInner1 */ ' ,
122
- [
120
+ ' function call nested in named arg [1] ' => [
121
+ 'testMarker ' => ' /* testNestedFunctionCallInner1 */ ' ,
122
+ ' parameters ' => [
123
123
'skip ' ,
124
124
],
125
125
],
126
- [
127
- '/* testNestedFunctionCallInner2 */ ' ,
128
- [
126
+ ' function call nested in named arg [2] ' => [
127
+ 'testMarker ' => ' /* testNestedFunctionCallInner2 */ ' ,
128
+ ' parameters ' => [
129
129
'array_or_countable ' ,
130
130
],
131
131
],
132
- [
133
- '/* testNamespaceRelativeFunction */ ' ,
134
- [
132
+ ' namespace relative function call ' => [
133
+ 'testMarker ' => ' /* testNamespaceRelativeFunction */ ' ,
134
+ ' parameters ' => [
135
135
'label ' ,
136
136
'more ' ,
137
137
],
138
138
],
139
- [
140
- '/* testPartiallyQualifiedFunction */ ' ,
141
- [
139
+ ' partially qualified function call ' => [
140
+ 'testMarker ' => ' /* testPartiallyQualifiedFunction */ ' ,
141
+ ' parameters ' => [
142
142
'label ' ,
143
143
'more ' ,
144
144
],
145
145
],
146
- [
147
- '/* testFullyQualifiedFunction */ ' ,
148
- [
146
+ ' fully qualified function call ' => [
147
+ 'testMarker ' => ' /* testFullyQualifiedFunction */ ' ,
148
+ ' parameters ' => [
149
149
'label ' ,
150
150
'more ' ,
151
151
],
152
152
],
153
- [
154
- '/* testVariableFunction */ ' ,
155
- [
153
+ ' variable function call ' => [
154
+ 'testMarker ' => ' /* testVariableFunction */ ' ,
155
+ ' parameters ' => [
156
156
'label ' ,
157
157
'more ' ,
158
158
],
159
159
],
160
- [
161
- '/* testVariableVariableFunction */ ' ,
162
- [
160
+ ' variable variable function call ' => [
161
+ 'testMarker ' => ' /* testVariableVariableFunction */ ' ,
162
+ ' parameters ' => [
163
163
'label ' ,
164
164
'more ' ,
165
165
],
166
166
],
167
- [
168
- '/* testMethodCall */ ' ,
169
- [
167
+ ' method call ' => [
168
+ 'testMarker ' => ' /* testMethodCall */ ' ,
169
+ ' parameters ' => [
170
170
'label ' ,
171
171
'more ' ,
172
172
],
173
173
],
174
- [
175
- '/* testVariableMethodCall */ ' ,
176
- [
174
+ ' variable method call ' => [
175
+ 'testMarker ' => ' /* testVariableMethodCall */ ' ,
176
+ ' parameters ' => [
177
177
'label ' ,
178
178
'more ' ,
179
179
],
180
180
],
181
- [
182
- '/* testClassInstantiation */ ' ,
183
- [
181
+ ' class instantiation ' => [
182
+ 'testMarker ' => ' /* testClassInstantiation */ ' ,
183
+ ' parameters ' => [
184
184
'label ' ,
185
185
'more ' ,
186
186
],
187
187
],
188
- [
189
- '/* testClassInstantiationSelf */ ' ,
190
- [
188
+ ' class instantiation with "self" ' => [
189
+ 'testMarker ' => ' /* testClassInstantiationSelf */ ' ,
190
+ ' parameters ' => [
191
191
'label ' ,
192
192
'more ' ,
193
193
],
194
194
],
195
- [
196
- '/* testClassInstantiationStatic */ ' ,
197
- [
195
+ ' class instantiation with "static" ' => [
196
+ 'testMarker ' => ' /* testClassInstantiationStatic */ ' ,
197
+ ' parameters ' => [
198
198
'label ' ,
199
199
'more ' ,
200
200
],
201
201
],
202
- [
203
- '/* testAnonClass */ ' ,
204
- [
202
+ ' anonymous class instantiation ' => [
203
+ 'testMarker ' => ' /* testAnonClass */ ' ,
204
+ ' parameters ' => [
205
205
'label ' ,
206
206
'more ' ,
207
207
],
208
208
],
209
- [
210
- '/* testNonAsciiNames */ ' ,
211
- [
209
+ ' function call with non-ascii characters in the variable name labels ' => [
210
+ 'testMarker ' => ' /* testNonAsciiNames */ ' ,
211
+ ' parameters ' => [
212
212
'💩💩💩 ' ,
213
213
'Пасха ' ,
214
214
'_valid ' ,
215
215
],
216
216
],
217
217
218
218
// Coding errors which should still be handled.
219
- [
220
- '/* testCompileErrorNamedBeforePositional */ ' ,
221
- [
219
+ ' invalid: named arg before positional (compile error) ' => [
220
+ 'testMarker ' => ' /* testCompileErrorNamedBeforePositional */ ' ,
221
+ ' parameters ' => [
222
222
'param ' ,
223
223
],
224
224
],
225
- [
226
- '/* testDuplicateName1 */ ' ,
227
- [
225
+ ' invalid: duplicate parameter name [1] ' => [
226
+ 'testMarker ' => ' /* testDuplicateName1 */ ' ,
227
+ ' parameters ' => [
228
228
'param ' ,
229
229
],
230
230
],
231
- [
232
- '/* testDuplicateName2 */ ' ,
233
- [
231
+ ' invalid: duplicate parameter name [2] ' => [
232
+ 'testMarker ' => ' /* testDuplicateName2 */ ' ,
233
+ ' parameters ' => [
234
234
'param ' ,
235
235
],
236
236
],
237
- [
238
- '/* testIncorrectOrderWithVariadic */ ' ,
239
- [
237
+ ' invalid: named arg before variadic (error exception) ' => [
238
+ 'testMarker ' => ' /* testIncorrectOrderWithVariadic */ ' ,
239
+ ' parameters ' => [
240
240
'start_index ' ,
241
241
],
242
242
],
243
- [
244
- '/* testCompileErrorIncorrectOrderWithVariadic */ ' ,
245
- [
243
+ ' invalid: named arg after variadic (compile error) ' => [
244
+ 'testMarker ' => ' /* testCompileErrorIncorrectOrderWithVariadic */ ' ,
245
+ ' parameters ' => [
246
246
'param ' ,
247
247
],
248
248
],
249
- [
250
- '/* testParseErrorNoValue */ ' ,
251
- [
249
+ ' invalid: named arg without value (parse error) ' => [
250
+ 'testMarker ' => ' /* testParseErrorNoValue */ ' ,
251
+ ' parameters ' => [
252
252
'param1 ' ,
253
253
'param2 ' ,
254
254
],
255
255
],
256
- [
257
- '/* testParseErrorExit */ ' ,
258
- [
256
+ ' invalid: named arg in exit() (parse error) ' => [
257
+ 'testMarker ' => ' /* testParseErrorExit */ ' ,
258
+ ' parameters ' => [
259
259
'status ' ,
260
260
],
261
261
],
262
- [
263
- '/* testParseErrorEmpty */ ' ,
264
- [
262
+ ' invalid: named arg in empty() (parse error) ' => [
263
+ 'testMarker ' => ' /* testParseErrorEmpty */ ' ,
264
+ ' parameters ' => [
265
265
'variable ' ,
266
266
],
267
267
],
268
- [
269
- '/* testParseErrorEval */ ' ,
270
- [
268
+ ' invalid: named arg in eval() (parse error) ' => [
269
+ 'testMarker ' => ' /* testParseErrorEval */ ' ,
270
+ ' parameters ' => [
271
271
'code ' ,
272
272
],
273
273
],
274
- [
275
- '/* testParseErrorArbitraryParentheses */ ' ,
276
- [
274
+ ' invalid: named arg in arbitrary parentheses (parse error) ' => [
275
+ 'testMarker ' => ' /* testParseErrorArbitraryParentheses */ ' ,
276
+ ' parameters ' => [
277
277
'something ' ,
278
278
],
279
279
],
@@ -318,26 +318,26 @@ public function testOtherTstringInFunctionCall($testMarker, $content)
318
318
*
319
319
* @see testOtherTstringInFunctionCall()
320
320
*
321
- * @return array
321
+ * @return array<string, array<string, string>>
322
322
*/
323
323
public static function dataOtherTstringInFunctionCall ()
324
324
{
325
325
return [
326
- [
327
- '/* testPositionalArgs */ ' ,
328
- 'START_INDEX ' ,
326
+ ' not arg name - global constant ' => [
327
+ 'testMarker ' => ' /* testPositionalArgs */ ' ,
328
+ 'content ' => ' START_INDEX ' ,
329
329
],
330
- [
331
- '/* testPositionalArgs */ ' ,
332
- 'COUNT ' ,
330
+ ' not arg name - fully qualified constant ' => [
331
+ 'testMarker ' => ' /* testPositionalArgs */ ' ,
332
+ 'content ' => ' COUNT ' ,
333
333
],
334
- [
335
- '/* testPositionalArgs */ ' ,
336
- 'VALUE ' ,
334
+ ' not arg name - namespace relative constant ' => [
335
+ 'testMarker ' => ' /* testPositionalArgs */ ' ,
336
+ 'content ' => ' VALUE ' ,
337
337
],
338
- [
339
- '/* testNestedFunctionCallInner2 */ ' ,
340
- 'count ' ,
338
+ ' not arg name - unqualified function call ' => [
339
+ 'testMarker ' => ' /* testNestedFunctionCallInner2 */ ' ,
340
+ 'content ' => ' count ' ,
341
341
],
342
342
];
343
343
@@ -716,9 +716,9 @@ public function testParseErrorVariableLabel()
716
716
* Verify that reserved keywords used as a parameter label are tokenized as T_PARAM_NAME
717
717
* and that the colon after it is tokenized as a T_COLON.
718
718
*
719
- * @param string $testMarker The comment prefacing the target token.
720
- * @param array $tokenTypes The token codes to look for.
721
- * @param string $tokenContent The token content to look for.
719
+ * @param string $testMarker The comment prefacing the target token.
720
+ * @param array<string|int> $tokenTypes The token codes to look for.
721
+ * @param string $tokenContent The token content to look for.
722
722
*
723
723
* @dataProvider dataReservedKeywordsAsName
724
724
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -768,7 +768,7 @@ public function testReservedKeywordsAsName($testMarker, $tokenTypes, $tokenConte
768
768
*
769
769
* @see testReservedKeywordsAsName()
770
770
*
771
- * @return array
771
+ * @return array<string, array<string|array<string|int>>>
772
772
*/
773
773
public static function dataReservedKeywordsAsName ()
774
774
{
0 commit comments