Skip to content

Incorrect behavior of ReadOnlyPropertyRector with conditional assignment in constructor #7857

@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/674bc158-9f21-481b-9c78-4ed12915a9f8

final class DemoFile
{
    private string $env;
    
    public function __construct(bool $sandbox)
    {
        if ($sandbox) {
            $this->env = 'sandbox';
        } else {
            $this->env = 'prod';
        }
    }
}

Expected Behaviour

The $env 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