Closed
Description
Description
Currently, PHPStan reports an error when a readonly property is not initialized and another error when not initialized in a constructor.
Class App\Foo has an uninitialized readonly property $validator. Assign it in the constructor.
Readonly property App\Foo::$validator is assigned outside of the constructor.
But with the attribute #[Required]
the DIC automatically call this method to initialize the property.
I think it could be a nice feature to remove these errors in that case.
Example
trait ValidationAwareCommandTrait
{
private readonly ValidatorInterface $validator;
#[Required]
public function setValidator(ValidatorInterface $validator): void
{
$this->validator = $validator;
}
}
Playground
Metadata
Metadata
Assignees
Labels
No labels