Skip to content

Incorrect behavior of RestoreDefaultNullToNullableTypePropertyRector #9021

@gitomato

Description

@gitomato

Bug Report

Rector adds a default value on a property hook.

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/e5dc1994-dc4a-4476-87fb-ec080ca08736

<?php

declare(strict_types=1);


interface Foo
{
    public ?string $bar { get; }
}

final class FooImpl implements Foo
{
    public ?string $bar {
        get => 'bar';
    }
}

Responsible rules

  • RestoreDefaultNullToNullableTypePropertyRector

Expected Behavior

Rector should not set a default value on a hooked property. As detected by PHPStan:

phpstan: Virtual hooked properties cannot have a default value

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions