File tree Expand file tree Collapse file tree 3 files changed +58
-3
lines changed
rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector Expand file tree Collapse file tree 3 files changed +58
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DowngradePhp81 \Rector \FunctionLike \DowngradeNeverTypeDeclarationRector \Fixture ;
4+
5+ use Rector \Tests \DowngradePhp81 \Rector \FunctionLike \DowngradeNeverTypeDeclarationRector \Source \SomeParentVoid ;
6+
7+ class WithParentIsVoid extends SomeParentVoid
8+ {
9+ public function run (): never
10+ {
11+ }
12+ }
13+
14+ ?>
15+ -----
16+ <?php
17+
18+ namespace Rector \Tests \DowngradePhp81 \Rector \FunctionLike \DowngradeNeverTypeDeclarationRector \Fixture ;
19+
20+ use Rector \Tests \DowngradePhp81 \Rector \FunctionLike \DowngradeNeverTypeDeclarationRector \Source \SomeParentVoid ;
21+
22+ class WithParentIsVoid extends SomeParentVoid
23+ {
24+ /**
25+ * @return never
26+ */
27+ public function run (): void
28+ {
29+ }
30+ }
31+
32+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \DowngradePhp81 \Rector \FunctionLike \DowngradeNeverTypeDeclarationRector \Source ;
6+
7+ class SomeParentVoid
8+ {
9+ public function run (): void
10+ {
11+ }
12+ }
Original file line number Diff line number Diff line change 1818use PHPStan \PhpDocParser \Ast \PhpDoc \ReturnTagValueNode ;
1919use PHPStan \Reflection \ClassReflection ;
2020use PHPStan \Type \MixedType ;
21+ use PHPStan \Type \NeverType ;
2122use PHPStan \Type \ObjectType ;
2223use PHPStan \Type \ThisType ;
2324use PHPStan \Type \Type ;
@@ -65,8 +66,10 @@ public function __construct(
6566 ];
6667 }
6768
68- public function decorateReturn (ClassMethod |Function_ |Closure |ArrowFunction $ functionLike ): void
69- {
69+ public function decorateReturn (
70+ ClassMethod |Function_ |Closure |ArrowFunction $ functionLike ,
71+ ?Type $ requireType = null
72+ ): void {
7073 if (! $ functionLike ->returnType instanceof Node) {
7174 return ;
7275 }
@@ -123,6 +126,14 @@ public function decorateReturn(ClassMethod|Function_|Closure|ArrowFunction $func
123126 $ functionLike ->returnType = new FullyQualified ($ returnType ->toString ());
124127 break ;
125128 }
129+
130+ if ($ requireType instanceof NeverType && $ returnType instanceof Identifier && $ this ->nodeNameResolver ->isName (
131+ $ returnType ,
132+ 'void '
133+ )) {
134+ $ functionLike ->returnType = new Identifier ('void ' );
135+ break ;
136+ }
126137 }
127138
128139 if (! $ this ->isRequireReturnTypeWillChange ($ classReflection , $ functionLike )) {
@@ -196,7 +207,7 @@ public function decorateReturnWithSpecificType(
196207 return false ;
197208 }
198209
199- $ this ->decorateReturn ($ functionLike );
210+ $ this ->decorateReturn ($ functionLike, $ requireType );
200211 return true ;
201212 }
202213
You can’t perform that action at this time.
0 commit comments