diff --git a/rules-tests/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector/Fixture/nullable_type_with_default_not_null.php.inc b/rules-tests/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector/Fixture/nullable_type_with_default_not_null.php.inc new file mode 100644 index 00000000000..d7120047e81 --- /dev/null +++ b/rules-tests/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector/Fixture/nullable_type_with_default_not_null.php.inc @@ -0,0 +1,24 @@ + +----- + diff --git a/rules/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector.php b/rules/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector.php index fbfec39ec9a..f8b3e82c929 100644 --- a/rules/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector.php +++ b/rules/DowngradePhp74/Rector/Property/DowngradeTypedPropertyRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\ComplexType; +use PhpParser\Node\Expr; use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\NullableType; @@ -66,7 +67,8 @@ public function refactor(Node $node): ?Node return null; } - if ($node->type instanceof NullableType) { + $default = $node->props[0]->default; + if ($node->type instanceof NullableType && $default instanceof Expr && $this->valueResolver->isNull($default)) { $node->props[0]->default = null; }