File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
rules-tests/TypeDeclarationDocblocks/Rector/Class_/ClassMethodArrayDocblockParamFromLocalCallsRector/Fixture
rules/TypeDeclarationDocblocks/Rector/Class_ Expand file tree Collapse file tree 2 files changed +59
-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 RemoveNullable
6+ {
7+ public function go ()
8+ {
9+ $ this ->run ($ this ->getNames ());
10+ }
11+
12+ private function run (array $ items )
13+ {
14+ }
15+
16+ /**
17+ * @return string[]|null
18+ */
19+ private function getNames (): ?array
20+ {
21+ return ['Jim ' , 'Rohn ' ];
22+ }
23+ }
24+
25+ ?>
26+ -----
27+ <?php
28+
29+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \Class_ \ClassMethodArrayDocblockParamFromLocalCallsRector \Fixture ;
30+
31+ final class RemoveNullable
32+ {
33+ public function go ()
34+ {
35+ $ this ->run ($ this ->getNames ());
36+ }
37+
38+ /**
39+ * @param string[] $items
40+ */
41+ private function run (array $ items )
42+ {
43+ }
44+
45+ /**
46+ * @return string[]|null
47+ */
48+ private function getNames (): ?array
49+ {
50+ return ['Jim ' , 'Rohn ' ];
51+ }
52+ }
53+
54+ ?>
Original file line number Diff line number Diff line change 99use PHPStan \PhpDocParser \Ast \PhpDoc \ParamTagValueNode ;
1010use PHPStan \Type \MixedType ;
1111use PHPStan \Type \Type ;
12+ use PHPStan \Type \TypeCombinator ;
1213use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1314use Rector \PhpParser \NodeFinder \LocalMethodCallFinder ;
1415use Rector \Rector \AbstractRector ;
@@ -112,10 +113,14 @@ public function refactor(Node $node): ?Node
112113 if (! $ resolvedParameterType instanceof Type) {
113114 continue ;
114115 }
116+
115117 if ($ resolvedParameterType instanceof MixedType) {
116118 continue ;
117119 }
118120
121+ // in case of array type declaration, null cannot be passed or is already casted
122+ $ resolvedParameterType = TypeCombinator::removeNull ($ resolvedParameterType );
123+
119124 $ hasClassMethodChanged = $ this ->nodeDocblockTypeDecorator ->decorateGenericIterableParamType (
120125 $ resolvedParameterType ,
121126 $ classMethodPhpDocInfo ,
You can’t perform that action at this time.
0 commit comments