@@ -53,7 +53,6 @@ public function __construct(
5353
5454 /**
5555 * @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
5756 * @param 'attribute'|'callable'|'method'|'staticMethod'|'function'|'new' $nodeType
5857 * @return list<IdentifierRuleError>
5958 */
@@ -62,9 +61,23 @@ public function check(
6261 Scope $ scope ,
6362 bool $ isBuiltin ,
6463 $ funcCall ,
65- array $ messages ,
6664 string $ nodeType ,
6765 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 ,
6881 ): array
6982 {
7083 $ functionParametersMinCount = 0 ;
@@ -204,7 +217,7 @@ public function check(
204217 ) {
205218 if ($ functionParametersMinCount === $ functionParametersMaxCount ) {
206219 $ errors [] = RuleErrorBuilder::message (sprintf (
207- $ invokedParametersCount === 1 ? $ messages [ 0 ] : $ messages [ 1 ] ,
220+ $ invokedParametersCount === 1 ? $ singleInsufficientParameterMessage : $ pluralInsufficientParametersMessage ,
208221 $ invokedParametersCount ,
209222 $ functionParametersMinCount ,
210223 ))
@@ -213,7 +226,7 @@ public function check(
213226 ->build ();
214227 } elseif ($ functionParametersMaxCount === -1 && $ invokedParametersCount < $ functionParametersMinCount ) {
215228 $ errors [] = RuleErrorBuilder::message (sprintf (
216- $ invokedParametersCount === 1 ? $ messages [ 2 ] : $ messages [ 3 ] ,
229+ $ invokedParametersCount === 1 ? $ singleInsufficientParameterInVariadicFunctionMessage : $ pluralInsufficientParametersInVariadicFunctionMessage ,
217230 $ invokedParametersCount ,
218231 $ functionParametersMinCount ,
219232 ))
@@ -222,7 +235,7 @@ public function check(
222235 ->build ();
223236 } elseif ($ functionParametersMaxCount !== -1 ) {
224237 $ errors [] = RuleErrorBuilder::message (sprintf (
225- $ invokedParametersCount === 1 ? $ messages [ 4 ] : $ messages [ 5 ] ,
238+ $ invokedParametersCount === 1 ? $ singleInsufficientParameterWithOptionalParametersMessage : $ pluralInsufficientParametersWithOptionalParametersMessage ,
226239 $ invokedParametersCount ,
227240 $ functionParametersMinCount ,
228241 $ functionParametersMaxCount ,
@@ -239,13 +252,13 @@ public function check(
239252 && !$ scope ->isInFirstLevelStatement ()
240253 && $ scope ->getKeepVoidType ($ funcCall )->isVoid ()->yes ()
241254 ) {
242- $ errors [] = RuleErrorBuilder::message ($ messages [ 7 ] )
255+ $ errors [] = RuleErrorBuilder::message ($ voidReturnTypeUsed )
243256 ->identifier (sprintf ('%s.void ' , $ nodeType ))
244257 ->line ($ funcCall ->getStartLine ())
245258 ->build ();
246259 }
247260
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 );
249262 foreach ($ addedErrors as $ error ) {
250263 $ errors [] = $ error ;
251264 }
@@ -290,17 +303,17 @@ public function check(
290303 }
291304 }
292305
293- if (!$ acceptsNamedArguments ->yes () && isset ( $ messages [ 14 ]) ) {
306+ if (!$ acceptsNamedArguments ->yes ()) {
294307 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 )))
296309 ->identifier ('argument.named ' )
297310 ->line ($ argumentLine )
298311 ->build ();
299312 } elseif ($ unpack ) {
300313 $ unpackedArrayType = $ scope ->getType ($ argumentValue );
301314 $ hasStringKey = $ unpackedArrayType ->getIterableKeyType ()->isString ();
302315 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 ' )))
304317 ->identifier ('argument.named ' )
305318 ->line ($ argumentLine )
306319 ->build ();
@@ -317,7 +330,7 @@ public function check(
317330 if (!$ accepts ->result ) {
318331 $ verbosityLevel = VerbosityLevel::getRecommendedLevelByType ($ parameterType , $ argumentValueType );
319332 $ errors [] = RuleErrorBuilder::message (sprintf (
320- $ messages [ 6 ] ,
333+ $ wrongArgumentTypeMessage ,
321334 $ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
322335 $ parameterType ->describe ($ verbosityLevel ),
323336 $ argumentValueType ->describe ($ verbosityLevel ),
@@ -331,12 +344,11 @@ public function check(
331344
332345 if (
333346 $ originalParameter !== null
334- && isset ($ messages [13 ])
335347 && !$ this ->unresolvableTypeHelper ->containsUnresolvableType ($ originalParameter ->getType ())
336348 && $ this ->unresolvableTypeHelper ->containsUnresolvableType ($ parameterType )
337349 ) {
338350 $ errors [] = RuleErrorBuilder::message (sprintf (
339- $ messages [ 13 ] ,
351+ $ unresolvableParameterTypeMessage ,
340352 $ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
341353 ))->identifier ('argument.unresolvableType ' )->line ($ argumentLine )->build ();
342354 }
@@ -348,7 +360,7 @@ public function check(
348360 && $ argumentValue ->static
349361 ) {
350362 $ errors [] = RuleErrorBuilder::message (sprintf (
351- $ messages [ 6 ] ,
363+ $ wrongArgumentTypeMessage ,
352364 $ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
353365 'bindable closure ' ,
354366 'static closure ' ,
@@ -368,7 +380,7 @@ public function check(
368380
369381 if ($ this ->nullsafeCheck ->containsNullSafe ($ argumentValue )) {
370382 $ errors [] = RuleErrorBuilder::message (sprintf (
371- $ messages [ 8 ] ,
383+ $ parameterPassedByReferenceMessage ,
372384 $ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
373385 ))
374386 ->identifier ('argument.byRef ' )
@@ -412,7 +424,7 @@ public function check(
412424 }
413425
414426 $ errors [] = RuleErrorBuilder::message (sprintf (
415- $ messages [ 8 ] ,
427+ $ parameterPassedByReferenceMessage ,
416428 $ this ->describeParameter ($ parameter , $ argumentName === null ? $ i + 1 : null ),
417429 ))->identifier ('argument.byRef ' )->line ($ argumentLine )->build ();
418430 }
@@ -469,7 +481,7 @@ static function (Type $type, callable $traverse) use (&$returnTemplateTypes): Ty
469481 continue ;
470482 }
471483
472- $ errors [] = RuleErrorBuilder::message (sprintf ($ messages [ 9 ] , $ name ))
484+ $ errors [] = RuleErrorBuilder::message (sprintf ($ unresolvableTemplateTypeMessage , $ name ))
473485 ->identifier ('argument.templateType ' )
474486 ->line ($ funcCall ->getStartLine ())
475487 ->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
481493 !$ this ->unresolvableTypeHelper ->containsUnresolvableType ($ originalParametersAcceptor ->getReturnType ())
482494 && $ this ->unresolvableTypeHelper ->containsUnresolvableType ($ parametersAcceptor ->getReturnType ())
483495 ) {
484- $ errors [] = RuleErrorBuilder::message ($ messages [ 12 ] )
496+ $ errors [] = RuleErrorBuilder::message ($ unresolvableReturnTypeMessage )
485497 ->identifier (sprintf ('%s.unresolvableReturnType ' , $ nodeType ))
486498 ->line ($ funcCall ->getStartLine ())
487499 ->build ();
0 commit comments