Bug Report
| Subject |
Details |
| Rector version |
0.15.1 |
| PHP version |
8.2.0 |
The rule CompleteDynamicPropertiesRector is adding the type when it's finding it but this may break code when the type is not specified in childrens or in parents class
Minimal PHP Code Causing Issue
https://getrector.org/demo/cf6e1124-bbdd-448c-b0e2-0f51fea5625b
class Hi {
public function hi() {
$this->message = "hi";
}
}
final class Hello extends Hi
{
public function hello()
{
return $this->message;
}
}
Expected Behaviour
I expect rector to add the type everywhere in all class inheritance tree, if it's the same attribute, but it doesn't...
This kind of behaviour seems like a problems with the phpstan's scope/context like explained in this comment:
- Due to PHPStan design that we inherit here, we can only work with current context. That means PHPStan does not know about all use cases, just about current class. E.g. dead public methods cannot be reported etc. This might change in the future, but so far there is nothing we can do about it.
So in this case, could it be possible to add a configure option to prevent rector to add the type everywhere? (or even just in a phpdoc ?)
It's not perfect but could still help a lot in code maintenance and prevent E_COMPILE_ERROR 😄
https://3v4l.org/XDWWQ