@@ -392,4 +392,63 @@ public function testReorderInvalid(
392392 $ this ->assertNull ($ normalized );
393393 }
394394
395+ public static function dataGetArgByPositionOrName (): iterable
396+ {
397+ // no arguments
398+ yield [[], 0 , 'array ' , null ];
399+
400+ // positional argument at the position
401+ yield [[null , null ], 0 , 'array ' , 0 ];
402+ yield [[null , null ], 1 , 'callback ' , 1 ];
403+
404+ // fewer positional arguments than the position
405+ yield [[null ], 1 , 'callback ' , null ];
406+
407+ // named argument written in signature order
408+ yield [['array ' , 'callback ' ], 0 , 'array ' , 0 ];
409+
410+ // named argument written in a different order
411+ yield [['callback ' , 'array ' ], 0 , 'array ' , 1 ];
412+ yield [['mode ' , 'callback ' , 'array ' ], 0 , 'array ' , 2 ];
413+
414+ // positional arguments followed by the named one
415+ yield [[null , 'mode ' , 'callback ' ], 1 , 'callback ' , 2 ];
416+
417+ // named argument at the position is bound to a different parameter
418+ yield [['callback ' ], 0 , 'array ' , null ];
419+ yield [[null , 'mode ' ], 1 , 'callback ' , null ];
420+
421+ // argument names are case-sensitive
422+ yield [['Array ' ], 0 , 'array ' , null ];
423+
424+ // negative position never matches a positional argument
425+ yield [[null , null ], -1 , 'array ' , null ];
426+ yield [[null , 'array ' ], -1 , 'array ' , 1 ];
427+ }
428+
429+ /**
430+ * @param list<?non-empty-string> $argumentNames
431+ */
432+ #[DataProvider('dataGetArgByPositionOrName ' )]
433+ public function testGetArgByPositionOrName (
434+ array $ argumentNames ,
435+ int $ position ,
436+ string $ name ,
437+ ?int $ expectedIndex ,
438+ ): void
439+ {
440+ $ arguments = [];
441+ foreach ($ argumentNames as $ argumentName ) {
442+ $ arguments [] = new Arg (new TypeExpr (new MixedType ()), name: $ argumentName === null ? null : new Identifier ($ argumentName ));
443+ }
444+
445+ $ arg = ArgumentsNormalizer ::getArgByPositionOrName ($ arguments , $ position , $ name );
446+ if ($ expectedIndex === null ) {
447+ $ this ->assertNull ($ arg );
448+ return ;
449+ }
450+
451+ $ this ->assertSame ($ arguments [$ expectedIndex ], $ arg );
452+ }
453+
395454}
0 commit comments