Skip to content

[php 8.1] ReadOnlyPropertyRector will apply to constructor params with hooks defined #9340

@tandev

Description

@tandev

Bug Report

Subject Details
Rector version last dev-main

Rector\Php81\Rector\Property\ReadOnlyPropertyRector will apply to hooks defined in constructor params

<?php
 final class SkipParamHook
 {
-    public function __construct(private string $foo {
+    public function __construct(private readonly string $foo {
         get {
             return $this->foo;
         }

But this is not valid as properties with hooks cannot have readonly property

for properties in general it was fixed already #9040

Minimal PHP Code Causing Issue

PHP 8.1

https://getrector.com/demo/018ac6a4-069c-411d-b7be-da07dc31841b

Expected Behaviour

rector skips rule if constructor param has hooks
See rectorphp/rector-src#7192

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