Skip to content

Incorrect behavior of ReadOnlyPropertyRector #8012

@Spomky

Description

@Spomky

Bug Report

Subject Details
Rector version 0.17.1
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/71ddafa6-c5f7-49b7-a33f-a80fdb945510

<?php

final class DemoFile
{
    private string $env;
    
    public function __construct()
    {
        $this->env = 'default';
    }
    
    public function getEnv(): string
    {
        return $this->env;
    }
    
    public static function create(string $env): self
    {
        $object = new self();
        $object->env = 'not default';
        return $object;
    }
}

Responsible rules

  • ReadOnlyPropertyRector

Expected Behavior

The property $env should not be considered as readonly as it is modified in a specific method.

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