File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
rules-tests/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector/Fixture Expand file tree Collapse file tree 2 files changed +45
-0
lines changed 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 FromExplode
6+ {
7+ public function go ()
8+ {
9+ $ this ->run (explode (': ' , '1:1 ' ));
10+ }
11+
12+ private function run (array $ items )
13+ {
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \ClassMethodArrayDocblockParamFromLocalCallsRector \Fixture ;
22+
23+ final class FromExplode
24+ {
25+ public function go ()
26+ {
27+ $ this ->run (explode (': ' , '1:1 ' ));
28+ }
29+
30+ /**
31+ * @param string[] $items
32+ */
33+ private function run (array $ items )
34+ {
35+ }
36+ }
37+
38+ ?>
Original file line number Diff line number Diff line change 3434use PHPStan \Type \Constant \ConstantBooleanType ;
3535use PHPStan \Type \Constant \ConstantStringType ;
3636use PHPStan \Type \ErrorType ;
37+ use PHPStan \Type \IntegerType ;
3738use PHPStan \Type \MixedType ;
3839use PHPStan \Type \NeverType ;
3940use PHPStan \Type \NullType ;
4041use PHPStan \Type \ObjectType ;
4142use PHPStan \Type \ObjectWithoutClassType ;
43+ use PHPStan \Type \StringType ;
4244use PHPStan \Type \ThisType ;
4345use PHPStan \Type \Type ;
4446use PHPStan \Type \TypeCombinator ;
@@ -178,6 +180,11 @@ public function getType(Node $node): Type
178180 }
179181 }
180182
183+ // correction for explode() that always returns array
184+ if ($ node instanceof FuncCall && $ node ->name instanceof Name && $ node ->name ->toString () === 'explode ' ) {
185+ return new ArrayType (new IntegerType (), new StringType ());
186+ }
187+
181188 if ($ node instanceof Ternary) {
182189 $ ternaryType = $ this ->resolveTernaryType ($ node );
183190 if (! $ ternaryType instanceof MixedType) {
You can’t perform that action at this time.
0 commit comments