@@ -53,7 +53,6 @@ public function __construct(
53
53
54
54
/**
55
55
* @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $funcCall
56
- * @param array{0: string, 1: string, 2: string, 3: string, 4: string, 5: string, 6: string, 7: string, 8: string, 9: string, 10: string, 11: string, 12: string, 13?: string, 14?: string} $messages
57
56
* @param 'attribute'|'callable'|'method'|'staticMethod'|'function'|'new' $nodeType
58
57
* @return list<IdentifierRuleError>
59
58
*/
@@ -62,9 +61,23 @@ public function check(
62
61
Scope $ scope ,
63
62
bool $ isBuiltin ,
64
63
$ funcCall ,
65
- array $ messages ,
66
64
string $ nodeType ,
67
65
TrinaryLogic $ acceptsNamedArguments ,
66
+ string $ singleInsufficientParameterMessage ,
67
+ string $ pluralInsufficientParametersMessage ,
68
+ string $ singleInsufficientParameterInVariadicFunctionMessage ,
69
+ string $ pluralInsufficientParametersInVariadicFunctionMessage ,
70
+ string $ singleInsufficientParameterWithOptionalParametersMessage ,
71
+ string $ pluralInsufficientParametersWithOptionalParametersMessage ,
72
+ string $ wrongArgumentTypeMessage ,
73
+ string $ voidReturnTypeUsed ,
74
+ string $ parameterPassedByReferenceMessage ,
75
+ string $ unresolvableTemplateTypeMessage ,
76
+ string $ missingParameterMessage ,
77
+ string $ unknownParameterMessage ,
78
+ string $ unresolvableReturnTypeMessage ,
79
+ string $ unresolvableParameterTypeMessage ,
80
+ string $ namedArgumentMessage ,
68
81
): array
69
82
{
70
83
$ functionParametersMinCount = 0 ;
@@ -204,7 +217,7 @@ public function check(
204
217
) {
205
218
if ($ functionParametersMinCount === $ functionParametersMaxCount ) {
206
219
$ errors [] = RuleErrorBuilder::message (sprintf (
207
- $ invokedParametersCount === 1 ? $ messages [ 0 ] : $ messages [ 1 ] ,
220
+ $ invokedParametersCount === 1 ? $ singleInsufficientParameterMessage : $ pluralInsufficientParametersMessage ,
208
221
$ invokedParametersCount ,
209
222
$ functionParametersMinCount ,
210
223
))
@@ -213,7 +226,7 @@ public function check(
213
226
->build ();
214
227
} elseif ($ functionParametersMaxCount === -1 && $ invokedParametersCount < $ functionParametersMinCount ) {
215
228
$ errors [] = RuleErrorBuilder::message (sprintf (
216
- $ invokedParametersCount === 1 ? $ messages [ 2 ] : $ messages [ 3 ] ,
229
+ $ invokedParametersCount === 1 ? $ singleInsufficientParameterInVariadicFunctionMessage : $ pluralInsufficientParametersInVariadicFunctionMessage ,
217
230
$ invokedParametersCount ,
218
231
$ functionParametersMinCount ,
219
232
))
@@ -222,7 +235,7 @@ public function check(
222
235
->build ();
223
236
} elseif ($ functionParametersMaxCount !== -1 ) {
224
237
$ errors [] = RuleErrorBuilder::message (sprintf (
225
- $ invokedParametersCount === 1 ? $ messages [ 4 ] : $ messages [ 5 ] ,
238
+ $ invokedParametersCount === 1 ? $ singleInsufficientParameterWithOptionalParametersMessage : $ pluralInsufficientParametersWithOptionalParametersMessage ,
226
239
$ invokedParametersCount ,
227
240
$ functionParametersMinCount ,
228
241
$ functionParametersMaxCount ,
@@ -239,13 +252,13 @@ public function check(
239
252
&& !$ scope ->isInFirstLevelStatement ()
240
253
&& $ scope ->getKeepVoidType ($ funcCall )->isVoid ()->yes ()
241
254
) {
242
- $ errors [] = RuleErrorBuilder::message ($ messages [ 7 ] )
255
+ $ errors [] = RuleErrorBuilder::message ($ voidReturnTypeUsed )
243
256
->identifier (sprintf ('%s.void ' , $ nodeType ))
244
257
->line ($ funcCall ->getStartLine ())
245
258
->build ();
246
259
}
247
260
248
- [$ addedErrors , $ argumentsWithParameters ] = $ this ->processArguments ($ parametersAcceptor , $ funcCall ->getStartLine (), $ isBuiltin , $ arguments , $ hasNamedArguments , $ messages [ 10 ] , $ messages [ 11 ] );
261
+ [$ addedErrors , $ argumentsWithParameters ] = $ this ->processArguments ($ parametersAcceptor , $ funcCall ->getStartLine (), $ isBuiltin , $ arguments , $ hasNamedArguments , $ missingParameterMessage , $ unknownParameterMessage );
249
262
foreach ($ addedErrors as $ error ) {
250
263
$ errors [] = $ error ;
251
264
}
@@ -290,17 +303,17 @@ public function check(
290
303
}
291
304
}
292
305
293
- if (!$ acceptsNamedArguments ->yes () && isset ( $ messages [ 14 ]) ) {
306
+ if (!$ acceptsNamedArguments ->yes ()) {
294
307
if ($ argumentName !== null ) {
295
- $ errors [] = RuleErrorBuilder::message (sprintf ($ messages [ 14 ] , sprintf ('named argument $%s ' , $ argumentName )))
308
+ $ errors [] = RuleErrorBuilder::message (sprintf ($ namedArgumentMessage , sprintf ('named argument $%s ' , $ argumentName )))
296
309
->identifier ('argument.named ' )
297
310
->line ($ argumentLine )
298
311
->build ();
299
312
} elseif ($ unpack ) {
300
313
$ unpackedArrayType = $ scope ->getType ($ argumentValue );
301
314
$ hasStringKey = $ unpackedArrayType ->getIterableKeyType ()->isString ();
302
315
if (!$ hasStringKey ->no ()) {
303
- $ errors [] = RuleErrorBuilder::message (sprintf ($ messages [ 14 ] , sprintf ('unpacked array with %s ' , $ hasStringKey ->yes () ? 'string key ' : 'possibly string key ' )))
316
+ $ errors [] = RuleErrorBuilder::message (sprintf ($ namedArgumentMessage , sprintf ('unpacked array with %s ' , $ hasStringKey ->yes () ? 'string key ' : 'possibly string key ' )))
304
317
->identifier ('argument.named ' )
305
318
->line ($ argumentLine )
306
319
->build ();
@@ -317,7 +330,7 @@ public function check(
317
330
if (!$ accepts ->result ) {
318
331
$ verbosityLevel = VerbosityLevel::getRecommendedLevelByType ($ parameterType , $ argumentValueType );
319
332
$ errors [] = RuleErrorBuilder::message (sprintf (
320
- $ messages [ 6 ] ,
333
+ $ wrongArgumentTypeMessage ,
321
334
$ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
322
335
$ parameterType ->describe ($ verbosityLevel ),
323
336
$ argumentValueType ->describe ($ verbosityLevel ),
@@ -331,12 +344,11 @@ public function check(
331
344
332
345
if (
333
346
$ originalParameter !== null
334
- && isset ($ messages [13 ])
335
347
&& !$ this ->unresolvableTypeHelper ->containsUnresolvableType ($ originalParameter ->getType ())
336
348
&& $ this ->unresolvableTypeHelper ->containsUnresolvableType ($ parameterType )
337
349
) {
338
350
$ errors [] = RuleErrorBuilder::message (sprintf (
339
- $ messages [ 13 ] ,
351
+ $ unresolvableParameterTypeMessage ,
340
352
$ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
341
353
))->identifier ('argument.unresolvableType ' )->line ($ argumentLine )->build ();
342
354
}
@@ -348,7 +360,7 @@ public function check(
348
360
&& $ argumentValue ->static
349
361
) {
350
362
$ errors [] = RuleErrorBuilder::message (sprintf (
351
- $ messages [ 6 ] ,
363
+ $ wrongArgumentTypeMessage ,
352
364
$ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
353
365
'bindable closure ' ,
354
366
'static closure ' ,
@@ -368,7 +380,7 @@ public function check(
368
380
369
381
if ($ this ->nullsafeCheck ->containsNullSafe ($ argumentValue )) {
370
382
$ errors [] = RuleErrorBuilder::message (sprintf (
371
- $ messages [ 8 ] ,
383
+ $ parameterPassedByReferenceMessage ,
372
384
$ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
373
385
))
374
386
->identifier ('argument.byRef ' )
@@ -412,7 +424,7 @@ public function check(
412
424
}
413
425
414
426
$ errors [] = RuleErrorBuilder::message (sprintf (
415
- $ messages [ 8 ] ,
427
+ $ parameterPassedByReferenceMessage ,
416
428
$ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
417
429
))->identifier ('argument.byRef ' )->line ($ argumentLine )->build ();
418
430
}
@@ -469,7 +481,7 @@ static function (Type $type, callable $traverse) use (&$returnTemplateTypes): Ty
469
481
continue ;
470
482
}
471
483
472
- $ errors [] = RuleErrorBuilder::message (sprintf ($ messages [ 9 ] , $ name ))
484
+ $ errors [] = RuleErrorBuilder::message (sprintf ($ unresolvableTemplateTypeMessage , $ name ))
473
485
->identifier ('argument.templateType ' )
474
486
->line ($ funcCall ->getStartLine ())
475
487
->tip ('See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type ' )
@@ -481,7 +493,7 @@ static function (Type $type, callable $traverse) use (&$returnTemplateTypes): Ty
481
493
!$ this ->unresolvableTypeHelper ->containsUnresolvableType ($ originalParametersAcceptor ->getReturnType ())
482
494
&& $ this ->unresolvableTypeHelper ->containsUnresolvableType ($ parametersAcceptor ->getReturnType ())
483
495
) {
484
- $ errors [] = RuleErrorBuilder::message ($ messages [ 12 ] )
496
+ $ errors [] = RuleErrorBuilder::message ($ unresolvableReturnTypeMessage )
485
497
->identifier (sprintf ('%s.unresolvableReturnType ' , $ nodeType ))
486
498
->line ($ funcCall ->getStartLine ())
487
499
->build ();
0 commit comments