Skip to content

Incorrect behavior of ReadOnlyPropertyRector #9040

@koraga

Description

@koraga

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/03e2e9fb-45b2-4e79-a30f-ef479e20bd5b

<?php

declare(strict_types=1);

final class Foo
{
    private int $propertyHook {
        get => random_int(1, 100);
        set => 1;
    }

    public function bar(): int
    {
        return $this->propertyHook * 1000;
    }
}

Responsible rules

  • ReadOnlyPropertyRector
  • ReadOnlyClassRector

Expected Behavior

ReadOnlyPropertyRector rule should not set readonly for property hooks

From documentation

Property hooks are incompatible with readonly properties. If there is a need to restrict access to a get or set operation in addition to altering its behavior, use asymmetric property visibility.

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