-
-
Notifications
You must be signed in to change notification settings - Fork 738
CompleteDynamicPropertiesRector is adding type in parents but not in children (and in the reverse order too) #7687
Copy link
Copy link
Closed
rectorphp/rector-src
#3248Labels
Description
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
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
Reactions are currently unavailable