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

ReadOnlyPropertyRector should not add readonly keyword to class properties which do not have native type in parent #6844

Closed
canvural opened this issue Nov 30, 2021 · 2 comments
Labels

Comments

@canvural
Copy link

Bug Report

Subject Details
Rector version 0.12.5

If a class has property without a native type, any child class can't declare the native type. PHP doesn't allow it. Also readonly is not allowed without native type. So Rector should not try to add readonly to child class property.

Minimal PHP Code Causing Issue

<?php

class Foo
{
    /** @var array */
	public $foo;
}

class Bar extends Foo
{
    /** @var array */
	public $foo = ['foo', 'bar'];
}

Expected Behaviour

Rector should not add readonly to foo property in class Bar.

Note: Demo site seems to run on PHP 8.0 still. So I couldn't manage to run the rector there. In any case this is the link: https://getrector.org/demo/1ec51e77-1a28-6c06-9386-1f9089bacc07

@canvural canvural added the bug label Nov 30, 2021
@canvural
Copy link
Author

Also maybe a separate bug, readonly keyword should not be added if the property has a default value.

@samsonasik
Copy link
Member

it seems already solved now, feel free to provide failing test case if you found other issue, thank you.

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

No branches or pull requests

2 participants