@@ -30,6 +30,9 @@ final class JsonValidateRector extends AbstractRector implements MinPhpVersionIn
3030 * @readonly
3131 */
3232 private BinaryOpManipulator $ binaryOpManipulator ;
33+ /**
34+ * @readonly
35+ */
3336 private ValueResolver $ valueResolver ;
3437 protected const ARG_NAMES = ['json ' , 'associative ' , 'depth ' , 'flags ' ];
3538 private const JSON_MAX_DEPTH = 0x7fffffff ;
@@ -51,7 +54,7 @@ public function getRuleDefinition() : RuleDefinition
5154CODE_SAMPLE
5255, <<<'CODE_SAMPLE'
5356if (json_validate($json)) {
54- }
57+ }
5558CODE_SAMPLE
5659)]);
5760 }
@@ -95,26 +98,26 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd) : ?FuncCall
9598 if (!$ booleanAnd ->left instanceof NotIdentical) {
9699 return null ;
97100 }
98- $ decodeMatch = $ this ->binaryOpManipulator ->matchFirstAndSecondConditionNode ($ booleanAnd ->left , fn ($ node ) => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_decode ' ), fn ($ node ) => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'null ' ));
101+ $ decodeMatch = $ this ->binaryOpManipulator ->matchFirstAndSecondConditionNode ($ booleanAnd ->left , fn (Node $ node ): bool => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_decode ' ), fn (Node $ node ): bool => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'null ' ));
99102 if (!$ decodeMatch instanceof TwoNodeMatch) {
100103 return null ;
101104 }
102105 // match: json_last_error() === JSON_ERROR_NONE OR JSON_ERROR_NONE === json_last_error()
103106 if (!$ booleanAnd ->right instanceof Identical) {
104107 return null ;
105108 }
106- $ errorMatch = $ this ->binaryOpManipulator ->matchFirstAndSecondConditionNode ($ booleanAnd ->right , fn ($ node ) => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_last_error ' ), fn ($ node ) => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'JSON_ERROR_NONE ' ));
109+ $ errorMatch = $ this ->binaryOpManipulator ->matchFirstAndSecondConditionNode ($ booleanAnd ->right , fn (Node $ node ): bool => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_last_error ' ), fn (Node $ node ): bool => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'JSON_ERROR_NONE ' ));
107110 if (!$ errorMatch instanceof TwoNodeMatch) {
108111 return null ;
109112 }
110113 // always return the json_decode(...) call
111- $ funcCall = $ decodeMatch ->getFirstExpr ();
112- if (!$ funcCall instanceof FuncCall) {
114+ $ expr = $ decodeMatch ->getFirstExpr ();
115+ if (!$ expr instanceof FuncCall) {
113116 return null ;
114117 }
115- return $ funcCall ;
118+ return $ expr ;
116119 }
117- protected function validateArgs (FuncCall $ funcCall ) : bool
120+ private function validateArgs (FuncCall $ funcCall ) : bool
118121 {
119122 $ depth = $ funcCall ->getArg ('depth ' , 2 );
120123 $ flags = $ funcCall ->getArg ('flags ' , 3 );
0 commit comments