Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of ReadOnlyPropertyRector #8844

Closed
tmvpobeda opened this issue Sep 27, 2024 · 0 comments · Fixed by rectorphp/rector-src#6331
Closed

Incorrect behavior of ReadOnlyPropertyRector #8844

tmvpobeda opened this issue Sep 27, 2024 · 0 comments · Fixed by rectorphp/rector-src#6331
Labels

Comments

@tmvpobeda
Copy link

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/4913fb48-87f2-46f2-b0d7-86e00af06b1e

<?php

class DemoFile
{
    public function __construct(
        private ?string $demoField1,
        private ?string $demoField2,
    ) {}
    
    public function getData(): array 
    {
        $data = [];
        if ($this->demoField2 !== null) {
            $data['demo_field_2'] = $this->demoField2;
        }
        
        return $data;
    }
}

Responsible rules

  • ReadOnlyPropertyRector

Expected Behavior

<?php

class DemoFile
{
    public function __construct(
        private readonly ?string $demoField1,
        private readonly ?string $demoField2,
    ) {}
    
    public function getData(): array 
    {
        $data = [];
        if ($this->demoField2 !== null) {
            $data['demo_field_2'] = $this->demoField2;
        }
        
        return $data;
    }
}

rector did not set property $demoField2 readonly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant