Skip to content

Incorrect behavior of ClassPropertyAssignToConstructorPromotionRector with property hooks #9232

@marcreichel

Description

@marcreichel

Bug Report

Subject Details
Rector version 2.1.0

When properties have property hooks and applying the Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector rule, the property hooks get removed.

Minimal PHP Code Causing Issue

https://getrector.com/demo/1fec18db-b50f-418f-9f54-c4584fca08ac

Expected Behaviour

The property hooks should stay as is but as a promoted property instead:

<?php

final class DemoFile
{
-   private string $foo {
-       get => strtotupper($this->foo);
-       set {
-           $this->foo = $value;
-       }
-   }
-   
    public function __construct(
+       private string $foo {
+           get => strtoupper($this->foo);
+           set {
+               $this->foo = $value;
+           }
+       },
-       string $foo,
    ) {
-       $this->foo = $foo;
    }
}

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