File tree Expand file tree Collapse file tree
rules-tests/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector/Fixture
rules/TypeDeclarationDocblocks/Rector/Class_ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \ClassMethodArrayDocblockParamFromLocalCallsRector \Fixture ;
4+
5+ final class MultipleCallsWithVariousTypes
6+ {
7+ public function go ()
8+ {
9+ $ this ->run (['item1 ' , 'item2 ' ]);
10+ $ this ->run ([123 , 456 ]);
11+ }
12+
13+ private function run (array $ items )
14+ {
15+ }
16+ }
17+
18+ ?>
19+ -----
20+ <?php
21+
22+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \ClassMethodArrayDocblockParamFromLocalCallsRector \Fixture ;
23+
24+ final class MultipleCallsWithVariousTypes
25+ {
26+ public function go ()
27+ {
28+ $ this ->run (['item1 ' , 'item2 ' ]);
29+ $ this ->run ([123 , 456 ]);
30+ }
31+
32+ /**
33+ * @param string[]|int[] $items
34+ */
35+ private function run (array $ items )
36+ {
37+ }
38+ }
39+
40+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \ClassMethodArrayDocblockParamFromLocalCallsRector \Fixture ;
4+
5+ class SkipNonArrayParam
6+ {
7+ public function go ()
8+ {
9+ $ this ->run (['item1 ' , 'item2 ' ]);
10+ }
11+
12+ private function run ($ items )
13+ {
14+ }
15+ }
Original file line number Diff line number Diff line change 77use PhpParser \Node ;
88use PhpParser \Node \Stmt \Class_ ;
99use PHPStan \PhpDocParser \Ast \PhpDoc \ParamTagValueNode ;
10- use PHPStan \Type \ArrayType ;
1110use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1211use Rector \Comments \NodeDocBlock \DocBlockUpdater ;
1312use Rector \PhpParser \NodeFinder \LocalMethodCallFinder ;
@@ -95,6 +94,10 @@ public function refactor(Node $node): ?Node
9594 $ classMethodParameterTypes = $ this ->callTypesResolver ->resolveStrictTypesFromCalls ($ methodCalls );
9695
9796 foreach ($ classMethod ->getParams () as $ parameterPosition => $ param ) {
97+ if ($ param ->type === null || ! $ this ->isName ($ param ->type , 'array ' )) {
98+ continue ;
99+ }
100+
98101 $ parameterName = $ this ->getName ($ param );
99102 $ parameterTagValueNode = $ classMethodPhpDocInfo ->getParamTagValueByName ($ parameterName );
100103
@@ -104,7 +107,7 @@ public function refactor(Node $node): ?Node
104107 }
105108
106109 $ resolvedParameterType = $ classMethodParameterTypes [$ parameterPosition ] ?? null ;
107- if (! $ resolvedParameterType instanceof ArrayType ) {
110+ if (! $ resolvedParameterType instanceof \ PHPStan \ Type \Type ) {
108111 continue ;
109112 }
110113
You can’t perform that action at this time.
0 commit comments