File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed
rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector
rules/TypeDeclarationDocblocks/Rector/ClassMethod Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockFromMethodCallDocblockRector \Fixture ;
6+
7+ use Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockFromMethodCallDocblockRector \Source \SomeRepository ;
8+
9+ final class HandleStaticCall
10+ {
11+ public function getAll (): array
12+ {
13+ return SomeRepository::staticFindAll ();
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ declare (strict_types=1 );
22+
23+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockFromMethodCallDocblockRector \Fixture ;
24+
25+ use Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \AddReturnDocblockFromMethodCallDocblockRector \Source \SomeRepository ;
26+
27+ final class HandleStaticCall
28+ {
29+ /**
30+ * @return SomeEntity[]
31+ */
32+ public function getAll (): array
33+ {
34+ return SomeRepository::staticFindAll ();
35+ }
36+ }
37+
38+ ?>
Original file line number Diff line number Diff line change @@ -21,4 +21,12 @@ public function findAllWithoutArray()
2121 {
2222 return [];
2323 }
24+
25+ /**
26+ * @return SomeEntity[]
27+ */
28+ public static function staticFindAll (): array
29+ {
30+ return [];
31+ }
2432}
Original file line number Diff line number Diff line change 66
77use PhpParser \Node ;
88use PhpParser \Node \Expr \MethodCall ;
9+ use PhpParser \Node \Expr \StaticCall ;
910use PhpParser \Node \Identifier ;
1011use PhpParser \Node \Stmt \ClassMethod ;
1112use PhpParser \Node \Stmt \Return_ ;
@@ -116,14 +117,16 @@ public function refactor(Node $node): ?Node
116117 }
117118
118119 $ onlyReturnWithExpr = $ this ->returnNodeFinder ->findOnlyReturnWithExpr ($ node );
119- if (! $ onlyReturnWithExpr instanceof Return_ || ! $ onlyReturnWithExpr ->expr instanceof MethodCall) {
120+ if (! $ onlyReturnWithExpr instanceof Return_ || ( ! $ onlyReturnWithExpr ->expr instanceof MethodCall && ! $ onlyReturnWithExpr -> expr instanceof StaticCall) ) {
120121 return null ;
121122 }
122123
123124 $ returnedMethodCall = $ onlyReturnWithExpr ->expr ;
124125
125126 // skip doctrine connection calls, as to generic and not helpful
126- $ callerType = $ this ->getType ($ returnedMethodCall ->var );
127+ $ callerType = $ this ->getType (
128+ $ returnedMethodCall instanceof MethodCall ? $ returnedMethodCall ->var : $ returnedMethodCall ->class
129+ );
127130 if ($ callerType instanceof ObjectType && $ callerType ->isInstanceOf (DoctrineClass::CONNECTION )->yes ()) {
128131 return null ;
129132 }
You can’t perform that action at this time.
0 commit comments