File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change 66use PhpParser \Node ;
77use PhpParser \NodeVisitorAbstract ;
88use PHPStan \DependencyInjection \AutowiredService ;
9- use function array_splice ;
109use function count ;
1110
1211#[AutowiredService]
@@ -27,14 +26,31 @@ public function enterNode(Node $node): ?Node
2726 return null ;
2827 }
2928
30- $ callbackPos = 0 ;
31- if ($ args [1 ]->name !== null && $ args [1 ]->name ->name === 'callback ' ) {
32- $ callbackPos = 1 ;
29+ $ callbackArg = null ;
30+ $ arrayArgs = [];
31+ foreach ($ args as $ i => $ arg ) {
32+ if ($ callbackArg === null ) {
33+ if ($ arg ->name === null && $ i === 0 ) {
34+ $ callbackArg = $ arg ;
35+ continue ;
36+ }
37+ if ($ arg ->name !== null && $ arg ->name ->toString () === 'callback ' ) {
38+ $ callbackArg = $ arg ;
39+ continue ;
40+ }
41+ }
42+
43+ $ arrayArgs [] = $ arg ;
44+ }
45+
46+ if ($ callbackArg !== null ) {
47+ $ callbackArg ->value ->setAttribute (self ::ATTRIBUTE_NAME , $ arrayArgs );
48+ return new Node \Expr \FuncCall (
49+ $ node ->name ,
50+ [$ callbackArg , ...$ arrayArgs ],
51+ $ node ->getAttributes (),
52+ );
3353 }
34- $ callbackArg = $ args [$ callbackPos ];
35- $ arrayArgs = $ args ;
36- array_splice ($ arrayArgs , $ callbackPos , 1 );
37- $ callbackArg ->value ->setAttribute (self ::ATTRIBUTE_NAME , $ arrayArgs );
3854
3955 return null ;
4056 }
Original file line number Diff line number Diff line change @@ -80,10 +80,6 @@ public static function selectFromArgs(
8080 && count ($ parametersAcceptors ) > 0
8181 ) {
8282 $ arrayMapArgs = $ args [0 ]->value ->getAttribute (ArrayMapArgVisitor::ATTRIBUTE_NAME );
83- if ($ arrayMapArgs === null && isset ($ args [1 ])) {
84- // callback argument of array_map() may be the second one (named argument)
85- $ arrayMapArgs = $ args [1 ]->value ->getAttribute (ArrayMapArgVisitor::ATTRIBUTE_NAME );
86- }
8783 if ($ arrayMapArgs !== null ) {
8884 $ acceptor = $ parametersAcceptors [0 ];
8985 $ parameters = $ acceptor ->getParameters ();
You can’t perform that action at this time.
0 commit comments