Skip to content

Incorrect behavior of ReadOnlyPropertyRector #7856

@yguedidi

Description

@yguedidi

Bug Report

Subject Details
Rector version: 0f0b93 - released at 2023-03-27 15:06

Minimal PHP Code Causing Issue

https://getrector.com/demo/03e903e4-92b0-445a-9066-ff52a95ae876

final class DemoFile
{
    private string|null $foo;
    
    public function _construct(string $string)
    {
        $this->foo = $string;
    }
    
    public function do(): void
    {
        $bar = '';
        
        if ($this->foo !== null) {
            $bar .= $this->foo;
        }
    }
}

Expected Behaviour

The $foo property should be marked as readonly

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