@@ -76,15 +76,16 @@ public function refactor(Node $node): ?Node
7676
7777 $ args = $ funcCall ->getArgs ();
7878 $ argPositions = $ this ->resolveArgPositions ($ args );
79-
79+
8080 $ funcCall ->name = new Name ('json_validate ' );
8181 $ funcCall ->args = [];
8282
83- foreach ($ argPositions as $ position ) {
84- if (! isset ($ args [$ position ])){
83+ foreach ($ argPositions as $ argPosition ) {
84+ if (! isset ($ args [$ argPosition ])) {
8585 continue ;
8686 }
87- $ funcCall ->args [$ position ] = $ args [$ position ];
87+
88+ $ funcCall ->args [$ argPosition ] = $ args [$ argPosition ];
8889 }
8990
9091 return $ funcCall ;
@@ -95,30 +96,6 @@ public function providePolyfillPackage(): string
9596 return PolyfillPackage::PHP_83 ;
9697 }
9798
98- /**
99- * @param Arg[] $args
100- */
101- private function resolveArgPositions (array $ args ): array
102- {
103- $ positions = [];
104- $ expectedNames = ['json ' , 'associative ' , 'depth ' , 'flags ' ];
105- foreach ($ args as $ position => $ arg ) {
106- if ($ arg ->name instanceof Identifier) {
107- $ name = $ arg ->name ->toString ();
108- if (in_array ($ name , $ expectedNames , true )) {
109- $ positions [$ name ] = $ position ;
110- }
111- }
112- }
113-
114- return [
115- 'json ' => 0 ,
116- 'associative ' => 1 ,
117- 'depth ' => 2 ,
118- 'flags ' => 3
119- ];
120- }
121-
12299 public function matchJsonValidateArg (BooleanAnd $ booleanAnd ): ?FuncCall
123100 {
124101 if ($ booleanAnd ->left instanceof NotIdentical) {
@@ -149,4 +126,28 @@ public function matchJsonValidateArg(BooleanAnd $booleanAnd): ?FuncCall
149126
150127 return null ;
151128 }
129+
130+ /**
131+ * @param PhpParser\Node\Arg[] $args
132+ */
133+ private function resolveArgPositions (array $ args ): array
134+ {
135+ $ positions = [];
136+ $ expectedNames = ['json ' , 'associative ' , 'depth ' , 'flags ' ];
137+ foreach ($ args as $ position => $ arg ) {
138+ if ($ arg ->name instanceof Identifier) {
139+ $ name = $ arg ->name ->toString ();
140+ if (in_array ($ name , $ expectedNames , true )) {
141+ $ positions [$ name ] = $ position ;
142+ }
143+ }
144+ }
145+
146+ return [
147+ 'json ' => 0 ,
148+ 'associative ' => 1 ,
149+ 'depth ' => 2 ,
150+ 'flags ' => 3 ,
151+ ];
152+ }
152153}
0 commit comments