1818use PhpParser \Node \Name \FullyQualified as NameFullyQualified ;
1919use PhpParser \Node \Stmt \Expression ;
2020use PhpParser \Node \Stmt \If_ ;
21- use PhpParser \Node \VariadicPlaceholder ;
2221use Rector \DowngradePhp72 \NodeManipulator \JsonConstCleaner ;
2322use Rector \Enum \JsonConstant ;
2423use Rector \NodeAnalyzer \DefineFuncCallAnalyzer ;
@@ -162,12 +161,16 @@ private function refactorExpression(Expression $expression): ?array
162161 }
163162
164163 // Nothing to do if not a refactored function
165- if (! in_array ($ this ->getName ($ funcCall ), self ::JSON_FUNCTIONS , true )) {
164+ if (! $ this ->isNames ($ funcCall , self ::JSON_FUNCTIONS )) {
165+ return null ;
166+ }
167+
168+ if ($ funcCall ->isFirstClassCallable ()) {
166169 return null ;
167170 }
168171
169172 // Nothing to do if the flag `JSON_THROW_ON_ERROR` is not set in args
170- if (! $ this ->hasConstFetchInArgs ($ funcCall ->args , 'JSON_THROW_ON_ERROR ' )) {
173+ if (! $ this ->hasConstFetchInArgs ($ funcCall ->getArgs () , 'JSON_THROW_ON_ERROR ' )) {
171174 return null ;
172175 }
173176
@@ -194,16 +197,11 @@ private function refactorExpression(Expression $expression): ?array
194197
195198 /**
196199 * Search if a given constant is set within a list of `Arg`
197- * @param array< Arg|VariadicPlaceholder> $args
200+ * @param Arg[] $args
198201 */
199202 private function hasConstFetchInArgs (array $ args , string $ constName ): bool
200203 {
201204 foreach ($ args as $ arg ) {
202- // Only `Arg` instances are handled.
203- if (! $ arg instanceof Arg) {
204- return false ;
205- }
206-
207205 $ value = $ arg ->value ;
208206
209207 if ($ value instanceof ConstFetch && $ this ->getName ($ value ) === $ constName ) {
0 commit comments