File tree Expand file tree Collapse file tree
rules/TypedCollections/Rector/ClassMethod
tests/Set/TypedCollections/Fixture Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ public function refactor(Node $node): ?ClassMethod
108108 // remove default param, as no longer needed
109109 if ($ firstParam ->default instanceof Expr) {
110110 $ firstParam ->default = null ;
111+
111112 return $ node ;
112113 }
113114
Original file line number Diff line number Diff line change 1616use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1717use Rector \Doctrine \Enum \DoctrineClass ;
1818use Rector \Doctrine \TypedCollections \DocBlockAnalyzer \CollectionTagValueNodeAnalyzer ;
19+ use Rector \NodeTypeResolver \Node \AttributeKey ;
1920use Rector \PHPUnit \NodeAnalyzer \TestsNodeAnalyzer ;
2021use Rector \Rector \AbstractRector ;
2122use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -120,6 +121,9 @@ public function refactor(Node $node): ?ClassMethod
120121 $ hasChanged = true ;
121122 $ param ->type = new FullyQualified (DoctrineClass::COLLECTION );
122123
124+ // fix reprint position of type
125+ $ param ->setAttribute (AttributeKey::ORIGINAL_NODE , null );
126+
123127 // make nullable only 1st param, as others might require a null
124128 if ($ param ->default instanceof Expr) {
125129 if ($ isInTests === false ) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Doctrine \Tests \Set \TypedCollections \Fixture ;
4+
5+ use Doctrine \Common \Collections \ArrayCollection ;
6+ use Doctrine \ODM \MongoDB \DocumentManager ;
7+
8+ final class ParamTypePosition
9+ {
10+ private array $ items ;
11+
12+ /**
13+ * @param mixed[]|ArrayCollection $collection
14+ */
15+ public function __construct (
16+ private readonly DocumentManager $ documentManager ,
17+ private $ collection
18+ ) {
19+ foreach ($ this ->collection as $ item ) {
20+ $ this ->items [] = $ item ;
21+ }
22+ }
23+ }
24+
25+ ?>
26+ -----
27+ <?php
28+
29+ namespace Rector \Doctrine \Tests \Set \TypedCollections \Fixture ;
30+
31+ use Doctrine \Common \Collections \Collection ;
32+ use Doctrine \Common \Collections \ArrayCollection ;
33+ use Doctrine \ODM \MongoDB \DocumentManager ;
34+
35+ final class ParamTypePosition
36+ {
37+ private array $ items ;
38+
39+ /**
40+ * @param Collection<int, mixed> $collection
41+ */
42+ public function __construct (
43+ private readonly DocumentManager $ documentManager ,
44+ private Collection $ collection
45+ ) {
46+ foreach ($ this ->collection as $ item ) {
47+ $ this ->items [] = $ item ;
48+ }
49+ }
50+ }
51+
52+ ?>
You can’t perform that action at this time.
0 commit comments