From 0f477e032d77d8d8079344a978212ad771bb7164 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Aug 2025 11:38:13 +0700 Subject: [PATCH] [DowngradePhp81] Handle parent is void on DowngradeNeverTypeDeclarationRector --- .../Fixture/with_parent_is_void.php.inc | 32 +++++++++++++++++++ .../Source/SomeParentVoid.php | 12 +++++++ .../PhpDocFromTypeDeclarationDecorator.php | 17 ++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/with_parent_is_void.php.inc create mode 100644 rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Source/SomeParentVoid.php diff --git a/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/with_parent_is_void.php.inc b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/with_parent_is_void.php.inc new file mode 100644 index 00000000..06982e4e --- /dev/null +++ b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/with_parent_is_void.php.inc @@ -0,0 +1,32 @@ + +----- + diff --git a/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Source/SomeParentVoid.php b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Source/SomeParentVoid.php new file mode 100644 index 00000000..5db90af1 --- /dev/null +++ b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Source/SomeParentVoid.php @@ -0,0 +1,12 @@ +returnType instanceof Node) { return; } @@ -123,6 +126,14 @@ public function decorateReturn(ClassMethod|Function_|Closure|ArrowFunction $func $functionLike->returnType = new FullyQualified($returnType->toString()); break; } + + if ($requireType instanceof NeverType && $returnType instanceof Identifier && $this->nodeNameResolver->isName( + $returnType, + 'void' + )) { + $functionLike->returnType = new Identifier('void'); + break; + } } if (! $this->isRequireReturnTypeWillChange($classReflection, $functionLike)) { @@ -196,7 +207,7 @@ public function decorateReturnWithSpecificType( return false; } - $this->decorateReturn($functionLike); + $this->decorateReturn($functionLike, $requireType); return true; }