Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TypedParams
function run3($optional = 1, null|int $required)
{
}

function run4($optional = 1, A&B $required)
{
}
}

?>
Expand All @@ -36,6 +40,10 @@ class TypedParams
function run3($optional = 1, null|int $required = null)
{
}

function run4($optional = 1, (A&B)|null $required = null)
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,37 @@ public function refactor(Node $node): ClassMethod|Function_|null
$hasChanged = true;

$param->default = new ConstFetch(new Name('null'));
$paramType = $param->type;

if (! $paramType instanceof Node) {
if (! $param->type instanceof Node) {
continue;
}

if ($paramType instanceof NullableType) {
if ($param->type instanceof NullableType) {
continue;
}

if ($paramType instanceof UnionType || $paramType instanceof IntersectionType) {
foreach ($paramType->types as $unionedType) {
if ($param->type instanceof UnionType) {
foreach ($param->type->types as $unionedType) {
if ($unionedType instanceof Identifier && $this->isName($unionedType, 'null')) {
continue 2;
}
}

$paramType->types[] = new Identifier('null');
$param->type->types[] = new Identifier('null');
continue;
}

if ($paramType instanceof ComplexType) {
if ($param->type instanceof IntersectionType) {
$param->type = new UnionType([$param->type, new Identifier('null')]);

continue;
}

if ($param->type instanceof ComplexType) {
continue;
}

$param->type = new NullableType($paramType);
$param->type = new NullableType($param->type);
}
}

Expand Down
Loading