diff --git a/rules-tests/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector/Fixture/in_arrow_function.php.inc b/rules-tests/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector/Fixture/in_arrow_function.php.inc new file mode 100644 index 00000000..7c1f830b --- /dev/null +++ b/rules-tests/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector/Fixture/in_arrow_function.php.inc @@ -0,0 +1,15 @@ + null; + +?> +----- + null; + +?> \ No newline at end of file diff --git a/rules/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector.php b/rules/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector.php index 2263f99e..f4d9afcd 100644 --- a/rules/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector.php +++ b/rules/DowngradePhp82/Rector/FunctionLike/DowngradeStandaloneNullTrueFalseReturnTypeRector.php @@ -9,8 +9,10 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\FunctionLike; use PhpParser\Node\Identifier; +use PhpParser\Node\NullableType; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; +use PhpParser\Node\UnionType; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\NullType; use PHPStan\Type\Type; @@ -118,7 +120,7 @@ private function resolveNativeType(Node $node, Node $returnType): Node { if ($node instanceof ClassMethod) { $returnTypeFromParent = $this->resolveParentNativeReturnType($node); - if ($returnTypeFromParent instanceof Node) { + if ($returnTypeFromParent instanceof UnionType || $returnTypeFromParent instanceof NullableType) { $this->traverseNodesWithCallable($returnTypeFromParent, static function (Node $subNode): void { $subNode->setAttribute(AttributeKey::ORIGINAL_NODE, null); });