@@ -34,7 +34,7 @@ final class JsonValidateRector extends AbstractRector implements MinPhpVersionIn
3434
3535 public function __construct (
3636 private readonly BinaryOpManipulator $ binaryOpManipulator ,
37- private ValueResolver $ valueResolver ,
37+ private readonly ValueResolver $ valueResolver ,
3838 ) {
3939 }
4040
@@ -57,7 +57,7 @@ public function getRuleDefinition(): RuleDefinition
5757 ,
5858 <<<'CODE_SAMPLE'
5959if (json_validate($json)) {
60- }
60+ }
6161CODE_SAMPLE
6262 ),
6363 ]
@@ -89,13 +89,14 @@ public function refactor(Node $node): ?Node
8989
9090 $ args = $ funcCall ->getArgs ();
9191
92- if (count ($ args ) < 1 ) {
92+ if (count ($ args ) < 1 ) {
9393 return null ;
9494 }
9595
9696 if (! $ this ->validateArgs ($ funcCall )) {
9797 return null ;
9898 }
99+
99100 $ funcCall ->name = new Name ('json_validate ' );
100101 $ funcCall ->args = $ args ;
101102
@@ -116,8 +117,8 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall
116117
117118 $ decodeMatch = $ this ->binaryOpManipulator ->matchFirstAndSecondConditionNode (
118119 $ booleanAnd ->left ,
119- fn ($ node ) => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_decode ' ),
120- fn ($ node ) => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'null ' )
120+ fn (Node $ node ): bool => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_decode ' ),
121+ fn (Node $ node ): bool => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'null ' )
121122 );
122123
123124 if (! $ decodeMatch instanceof TwoNodeMatch) {
@@ -131,23 +132,24 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall
131132
132133 $ errorMatch = $ this ->binaryOpManipulator ->matchFirstAndSecondConditionNode (
133134 $ booleanAnd ->right ,
134- fn ($ node ) => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_last_error ' ),
135- fn ($ node ) => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'JSON_ERROR_NONE ' )
135+ fn (Node $ node ): bool => $ node instanceof FuncCall && $ this ->isName ($ node ->name , 'json_last_error ' ),
136+ fn (Node $ node ): bool => $ node instanceof ConstFetch && $ this ->isName ($ node ->name , 'JSON_ERROR_NONE ' )
136137 );
137138
138139 if (! $ errorMatch instanceof TwoNodeMatch) {
139140 return null ;
140141 }
141142
142143 // always return the json_decode(...) call
143- $ funcCall = $ decodeMatch ->getFirstExpr ();
144- if (! $ funcCall instanceof FuncCall) {
144+ $ expr = $ decodeMatch ->getFirstExpr ();
145+ if (! $ expr instanceof FuncCall) {
145146 return null ;
146147 }
147- return $ funcCall ;
148+
149+ return $ expr ;
148150 }
149151
150- protected function validateArgs (FuncCall $ funcCall ): bool
152+ private function validateArgs (FuncCall $ funcCall ): bool
151153 {
152154 $ depth = $ funcCall ->getArg ('depth ' , 2 );
153155 $ flags = $ funcCall ->getArg ('flags ' , 3 );
0 commit comments