File tree Expand file tree Collapse file tree
rules-tests/TypeDeclaration/Rector/ClassMethod/AddReturnArrayDocblockBasedOnArrayMapRector/Fixture
rules/TypeDeclaration/Rector/ClassMethod Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \AddReturnArrayDocblockBasedOnArrayMapRector \Fixture ;
4+
5+ final class OverrideMixed
6+ {
7+ /**
8+ * @param array $items
9+ * @return mixed[]
10+ */
11+ public function process (array $ items )
12+ {
13+ return array_map (function ($ item ): int {
14+ return $ item ;
15+ }, $ items );
16+ }
17+ }
18+
19+ ?>
20+ -----
21+ <?php
22+
23+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \AddReturnArrayDocblockBasedOnArrayMapRector \Fixture ;
24+
25+ final class OverrideMixed
26+ {
27+ /**
28+ * @param array $items
29+ * @return int[]
30+ */
31+ public function process (array $ items )
32+ {
33+ return array_map (function ($ item ): int {
34+ return $ item ;
35+ }, $ items );
36+ }
37+ }
38+
39+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \AddReturnArrayDocblockBasedOnArrayMapRector \Fixture ;
4+
5+ final class SkipOverride
6+ {
7+ /**
8+ * @param array $items
9+ * @return positive-int[]
10+ */
11+ public function process (array $ items )
12+ {
13+ return array_map (function ($ item ): int {
14+ return $ item ;
15+ }, $ items );
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -127,7 +127,12 @@ public function refactor(Node $node): null|Function_|ClassMethod
127127 $ functionLikePhpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ node );
128128
129129 $ returnOriginalType = $ functionLikePhpDocInfo ->getReturnType ();
130- if ($ returnOriginalType instanceof IntersectionType && $ returnOriginalType ->isArray ()->yes ()) {
130+
131+ if ($ returnOriginalType instanceof ArrayType && ! $ returnOriginalType ->getItemType () instanceof MixedType) {
132+ return null ;
133+ }
134+
135+ if ($ returnOriginalType instanceof IntersectionType) {
131136 return null ;
132137 }
133138
You can’t perform that action at this time.
0 commit comments