File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
rules-tests/TypeDeclaration/Rector/ClassMethod/NarrowObjectReturnTypeRector/Fixture
rules/TypeDeclaration/Rector/ClassMethod Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \NarrowObjectReturnTypeRector \Fixture ;
4+
5+ use Rector \Tests \TypeDeclaration \Rector \ClassMethod \NarrowObjectReturnTypeRector \Source \ConferenceTalk ;
6+
7+ class NonFinalClassWithFinalMethod
8+ {
9+ final public function create (): object
10+ {
11+ return new ConferenceTalk ();
12+ }
13+ }
14+
15+ ?>
16+ -----
17+ <?php
18+
19+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \NarrowObjectReturnTypeRector \Fixture ;
20+
21+ use Rector \Tests \TypeDeclaration \Rector \ClassMethod \NarrowObjectReturnTypeRector \Source \ConferenceTalk ;
22+
23+ class NonFinalClassWithFinalMethod
24+ {
25+ final public function create (): \Rector \Tests \TypeDeclaration \Rector \ClassMethod \NarrowObjectReturnTypeRector \Source \ConferenceTalk
26+ {
27+ return new ConferenceTalk ();
28+ }
29+ }
30+
31+ ?>
Original file line number Diff line number Diff line change 88use PhpParser \Node \Identifier ;
99use PhpParser \Node \Name \FullyQualified ;
1010use PhpParser \Node \Stmt \ClassMethod ;
11- use PhpParser \Node \Stmt \Return_ ;
1211use PHPStan \Reflection \ClassReflection ;
1312use PHPStan \Type \ObjectType ;
1413use Rector \PhpParser \Node \BetterNodeFinder ;
@@ -109,7 +108,7 @@ public function refactor(Node $node): ?Node
109108 return null ;
110109 }
111110
112- if (! $ classReflection ->isFinal ()) {
111+ if (! $ classReflection ->isFinal () && ! $ node -> isFinal () ) {
113112 return null ;
114113 }
115114
@@ -226,7 +225,7 @@ private function hasParentMethodWithNonObjectReturn(ClassMethod $classMethod): b
226225
227226 private function getActualReturnClass (ClassMethod $ node ): ?string
228227 {
229- $ returnStatements = $ this ->betterNodeFinder ->findInstanceOf ($ node, Return_::class );
228+ $ returnStatements = $ this ->betterNodeFinder ->findReturnsScoped ($ node );
230229
231230 if ($ returnStatements === []) {
232231 return null ;
You can’t perform that action at this time.
0 commit comments