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 ;
@@ -119,9 +118,9 @@ private function markConstantKnownInInnerStmts(If_ $if): void
119118 SimpleNodeTraverser::decorateWithAttributeValue ($ if , self ::PHP73_JSON_CONSTANT_IS_KNOWN , true );
120119 }
121120
122- private function resolveFuncCall (Expression $ Expression ): ?FuncCall
121+ private function resolveFuncCall (Expression $ expression ): ?FuncCall
123122 {
124- $ expr = $ Expression ->expr ;
123+ $ expr = $ expression ->expr ;
125124 if ($ expr instanceof Assign) {
126125 if ($ expr ->expr instanceof FuncCall) {
127126 return $ expr ->expr ;
@@ -153,21 +152,22 @@ private function refactorExpression(Expression $expression): ?array
153152 return null ;
154153 }
155154
156- // retrieve a `FuncCall`, if any, from the statement
157155 $ funcCall = $ this ->resolveFuncCall ($ expression );
158-
159- // Nothing to do if no `FuncCall` found
160156 if (! $ funcCall instanceof FuncCall) {
161157 return null ;
162158 }
163159
160+ if ($ funcCall ->isFirstClassCallable ()) {
161+ return null ;
162+ }
163+
164164 // Nothing to do if not a refactored function
165- if (! in_array ( $ this ->getName ($ funcCall) , self ::JSON_FUNCTIONS , true )) {
165+ if (! $ this ->isNames ($ funcCall , self ::JSON_FUNCTIONS )) {
166166 return null ;
167167 }
168168
169169 // 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 ' )) {
170+ if (! $ this ->hasConstFetchInArgs ($ funcCall ->getArgs () , 'JSON_THROW_ON_ERROR ' )) {
171171 return null ;
172172 }
173173
@@ -194,18 +194,12 @@ private function refactorExpression(Expression $expression): ?array
194194
195195 /**
196196 * Search if a given constant is set within a list of `Arg`
197- * @param array< Arg|VariadicPlaceholder> $args
197+ * @param Arg[] $args
198198 */
199199 private function hasConstFetchInArgs (array $ args , string $ constName ): bool
200200 {
201201 foreach ($ args as $ arg ) {
202- // Only `Arg` instances are handled.
203- if (! $ arg instanceof Arg) {
204- return false ;
205- }
206-
207202 $ value = $ arg ->value ;
208-
209203 if ($ value instanceof ConstFetch && $ this ->getName ($ value ) === $ constName ) {
210204 return true ;
211205 }
0 commit comments