@@ -106,6 +106,15 @@ public function getNodeTypes(): array
106106 */
107107 public function refactor (Node $ node ): ?Node
108108 {
109+ if ($ node ->params === []) {
110+ return null ;
111+ }
112+
113+ // has params with at least one missing type
114+ if (! $ this ->hasAtLeastOneParamWithoutType ($ node )) {
115+ return null ;
116+ }
117+
109118 if ($ node instanceof ClassMethod && $ this ->shouldSkipClassMethod ($ node )) {
110119 return null ;
111120 }
@@ -116,7 +125,17 @@ public function refactor(Node $node): ?Node
116125 [StaticCall::class, MethodCall::class, FuncCall::class]
117126 );
118127
119- $ hasChanged = $ this ->refactorFunctionLike ($ node , $ callers );
128+ // keep only callers with args
129+ $ callersWithArgs = array_filter (
130+ $ callers ,
131+ fn (StaticCall |MethodCall |FuncCall $ caller ): bool => $ caller ->args !== []
132+ );
133+
134+ if ($ callersWithArgs === []) {
135+ return null ;
136+ }
137+
138+ $ hasChanged = $ this ->refactorFunctionLike ($ node , $ callersWithArgs );
120139 if ($ hasChanged ) {
121140 return $ node ;
122141 }
@@ -126,10 +145,6 @@ public function refactor(Node $node): ?Node
126145
127146 private function shouldSkipClassMethod (ClassMethod $ classMethod ): bool
128147 {
129- if ($ classMethod ->params === []) {
130- return true ;
131- }
132-
133148 $ isMissingParameterTypes = false ;
134149 foreach ($ classMethod ->params as $ param ) {
135150 if ($ param ->type instanceof Node) {
@@ -218,4 +233,15 @@ private function refactorFunctionLike(
218233
219234 return $ hasChanged ;
220235 }
236+
237+ private function hasAtLeastOneParamWithoutType (ClassMethod |Function_ |Closure |ArrowFunction $ functionLike ): bool
238+ {
239+ foreach ($ functionLike ->params as $ param ) {
240+ if (! $ param ->type instanceof Node) {
241+ return true ;
242+ }
243+ }
244+
245+ return false ;
246+ }
221247}
0 commit comments