PromotedConstructorPropertyFixer doesn't understand inheritance
Closed this issue · 4 comments
Bilge commented
I was excited to use PromotedConstructorPropertyFixer
but unfortunately it is incomplete as it does not support or understand object inheritance.
class A {
protected $foo;
}
class B extends A {
public function __construct($foo) {
$this->foo = $foo;
}
}
class B extends A {
- public function __construct($foo) {
+ public function __construct(public $foo) {
- $this->foo = $foo;
}
}
kubawerlos commented
It's is not possible to discover such cases when child and parent classes are in separate files.
I'm thinking about adding option promote_only_existing_properties
, WDYT @Bilge?
Bilge commented
I suppose that should be good enough.
Bilge commented
Isn't it the case that you always have the option to use reflection?
kubawerlos commented
Not really, PHP CS Fixer does not have a knowledge of other files when fixing one.
That would lead to non-deterministic behaviour - once the class would be found, other time might not.