55namespace Rector \Php85 \Rector \FuncCall ;
66
77use PhpParser \Node ;
8- use PhpParser \Node \Arg ;
9- use PhpParser \Node \Expr \CallLike ;
108use PhpParser \Node \Expr \FuncCall ;
119use PhpParser \Node \Expr \MethodCall ;
1210use PhpParser \Node \Identifier ;
@@ -58,6 +56,10 @@ public function getNodeTypes(): array
5856 */
5957 public function refactor (Node $ node ): ?Node
6058 {
59+ if ($ node ->isFirstClassCallable ()) {
60+ return null ;
61+ }
62+
6163 if ($ node instanceof FuncCall && ! $ this ->isName ($ node ->name , 'finfo_buffer ' )) {
6264 return null ;
6365 }
@@ -82,10 +84,7 @@ public function provideMinPhpVersion(): int
8284 return PhpVersionFeature::DEPRECATE_FINFO_BUFFER_CONTEXT ;
8385 }
8486
85- /**
86- * @param FuncCall|MethodCall $callLike
87- */
88- private function removeContextArg (CallLike $ callLike ): bool
87+ private function removeContextArg (FuncCall |MethodCall $ callLike ): bool
8988 {
9089 // In `finfo::buffer` method calls, the first parameter, compared to `finfo_buffer`, does not exist.
9190 $ methodArgCorrection = 0 ;
@@ -97,15 +96,7 @@ private function removeContextArg(CallLike $callLike): bool
9796 return false ;
9897 }
9998
100- // Cannot handle variadic args
101- foreach ($ callLike ->args as $ position => $ arg ) {
102- if (! $ arg instanceof Arg) {
103- return false ;
104- }
105- }
106-
107- /** @var array<Arg> $args */
108- $ args = $ callLike ->args ;
99+ $ args = $ callLike ->getArgs ();
109100
110101 // Argument 3 ($flags) and argument 4 ($context) are optional, thus named parameters must be considered
111102 if (! $ this ->argsAnalyzer ->hasNamedArg ($ args )) {
@@ -119,7 +110,7 @@ private function removeContextArg(CallLike $callLike): bool
119110 }
120111
121112 foreach ($ args as $ position => $ arg ) {
122- if ($ arg ->name instanceof Identifier && $ arg -> name ->name === 'context ' ) {
113+ if ($ arg ->name instanceof Identifier && $ this -> isName ( $ arg ->name , 'context ' ) ) {
123114 unset($ callLike ->args [$ position ]);
124115
125116 return true ;
0 commit comments