File tree Expand file tree Collapse file tree 3 files changed +79
-6
lines changed
rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForJsonArrayRector/Fixture
rules/TypeDeclarationDocblocks/Rector/ClassMethod Expand file tree Collapse file tree 3 files changed +79
-6
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockForJsonArrayRector \Fixture ;
6+
7+ use Nette \Utils \Json ;
8+
9+ final class JsonUtilsWithNamedArg
10+ {
11+ public function provide (string $ contents ): array
12+ {
13+ return Json::decode (forceArrays: true , json: $ contents );
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ declare (strict_types=1 );
22+
23+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockForJsonArrayRector \Fixture ;
24+
25+ use Nette \Utils \Json ;
26+
27+ final class JsonUtilsWithNamedArg
28+ {
29+ /**
30+ * @return array<string, mixed>
31+ */
32+ public function provide (string $ contents ): array
33+ {
34+ return Json::decode (forceArrays: true , json: $ contents );
35+ }
36+ }
37+
38+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockForJsonArrayRector \Fixture ;
6+
7+ final class WithNamedArg
8+ {
9+ public function provide (string $ contents ): array
10+ {
11+ return json_decode (associative: true , json: $ contents );
12+ }
13+ }
14+
15+ ?>
16+ -----
17+ <?php
18+
19+ declare (strict_types=1 );
20+
21+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockForJsonArrayRector \Fixture ;
22+
23+ final class WithNamedArg
24+ {
25+ /**
26+ * @return array<string, mixed>
27+ */
28+ public function provide (string $ contents ): array
29+ {
30+ return json_decode (associative: true , json: $ contents );
31+ }
32+ }
33+
34+ ?>
Original file line number Diff line number Diff line change 55namespace Rector \TypeDeclarationDocblocks \Rector \ClassMethod ;
66
77use PhpParser \Node ;
8+ use PhpParser \Node \Arg ;
89use PhpParser \Node \Expr ;
910use PhpParser \Node \Expr \FuncCall ;
1011use PhpParser \Node \Expr \StaticCall ;
@@ -139,12 +140,12 @@ private function isJsonDecodeToArray(Expr $expr): bool
139140 return false ;
140141 }
141142
142- if (count ($ expr ->getArgs ()) !== 2 ) {
143+ $ arg = $ expr ->getArg ('associative ' , 1 );
144+ if (! $ arg instanceof Arg) {
143145 return false ;
144146 }
145147
146- $ secondArg = $ expr ->getArgs ()[1 ];
147- return $ this ->valueResolver ->isTrue ($ secondArg ->value );
148+ return $ this ->valueResolver ->isTrue ($ arg ->value );
148149 }
149150
150151 if ($ expr instanceof StaticCall) {
@@ -160,12 +161,12 @@ private function isJsonDecodeToArray(Expr $expr): bool
160161 return false ;
161162 }
162163
163- if (count ($ expr ->getArgs ()) !== 2 ) {
164+ $ arg = $ expr ->getArg ('forceArrays ' , 1 );
165+ if (! $ arg instanceof Arg) {
164166 return false ;
165167 }
166168
167- $ secondArg = $ expr ->getArgs ()[1 ];
168- return $ this ->valueResolver ->isTrue ($ secondArg ->value );
169+ return $ this ->valueResolver ->isTrue ($ arg ->value );
169170 }
170171
171172 return false ;
You can’t perform that action at this time.
0 commit comments