@@ -102,13 +102,8 @@ public function refactor(Node $node): null|Expr|array
102102 return null ;
103103 }
104104
105- // if ($node instanceof TryCatch) {
106- // SimpleNodeTraverser::decorateWithAttributeValue($node->stmts, self::IS_EXPRESSION_INSIDE_TRY_CATCH, true);
107- // return null;
108- // }
109-
110105 if ($ node instanceof Expression) {
111- return $ this ->refactorStmt ($ node );
106+ return $ this ->refactorExpression ($ node );
112107 }
113108
114109 return $ this ->jsonConstCleaner ->clean ($ node , [JsonConstant::THROW_ON_ERROR ]);
@@ -154,14 +149,14 @@ private function resolveFuncCall(Expression $Expression): ?FuncCall
154149 *
155150 * @return null|array<Expression|If_>
156151 */
157- private function refactorStmt (Expression $ Expression ): ?array
152+ private function refactorExpression (Expression $ expression ): ?array
158153 {
159- if ($ Expression ->getAttribute (AttributeKey::IS_IN_TRY_BLOCK ) === true ) {
154+ if ($ expression ->getAttribute (AttributeKey::IS_IN_TRY_BLOCK ) === true ) {
160155 return null ;
161156 }
162157
163158 // retrieve a `FuncCall`, if any, from the statement
164- $ funcCall = $ this ->resolveFuncCall ($ Expression );
159+ $ funcCall = $ this ->resolveFuncCall ($ expression );
165160
166161 // Nothing to do if no `FuncCall` found
167162 if (! $ funcCall instanceof FuncCall) {
@@ -178,7 +173,7 @@ private function refactorStmt(Expression $Expression): ?array
178173 return null ;
179174 }
180175
181- $ nodes = [$ Expression ];
176+ $ nodes = [$ expression ];
182177 $ nodes [] = new If_ (
183178 new NotIdentical (
184179 new FuncCall (new Name ('json_last_error ' )),
@@ -228,26 +223,18 @@ private function hasConstFetchInArgs(array $args, string $constName): bool
228223 /**
229224 * Search if a given constant is set within a `BitwiseOr`
230225 */
231- private function hasConstFetchInBitwiseOr (BitwiseOr $ bitwiseOr , string $ constName ): bool
226+ private function hasConstFetchInBitwiseOr (BitwiseOr $ bitwiseOr , string $ constantName ): bool
232227 {
233- $ found = false ;
234-
235228 foreach ([$ bitwiseOr ->left , $ bitwiseOr ->right ] as $ subNode ) {
236- $ found = match (true ) {
237- $ subNode instanceof BitwiseOr => (
238- $ this ->hasConstFetchInBitwiseOr ($ subNode , $ constName )
239- ),
240- $ subNode instanceof ConstFetch => (
241- $ this ->getName ($ subNode ) === $ constName
242- ),
243- default => false
244- };
229+ if ($ subNode instanceof BitwiseOr && $ this ->hasConstFetchInBitwiseOr ($ subNode , $ constantName )) {
230+ return true ;
231+ }
245232
246- if ($ found ) {
247- break ;
233+ if ($ subNode instanceof ConstFetch && $ this -> isName ( $ subNode , $ constantName ) ) {
234+ return true ;
248235 }
249236 }
250237
251- return $ found ;
238+ return false ;
252239 }
253240}
0 commit comments