-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Summary
Hello,
The IDE Helper marks a property as nullable only when the corresponding database field is nullable. But in reality, when we create a new, empty model, all properties are effectively nullable. The PHPDoc generated by the IDE Helper only reflects the state of a model after it has been retrieved from the database.
From a pure PHP perspective, this isn’t correct, because any property can be null when the class is first instantiated.
I have an “edge case” where many of my attributes are read-only and depend on other attributes. For example:
protected function foo(): Attribute
{
return Attribute::make(
get: fn (): ?string => $this->bar !== null ? $this->bar->description() : null,
);
}
I need to check whether $this->bar !== null before calling a deeper method to avoid errors when accessing this property on a freshly initialized model.
However, I also use PHPStan, which raises an error because, based on the model’s PHPDoc, the check is unnecessary — it assumes bar is not nullable.
So… my question is: is there any way to tell the IDE Helper to mark all properties as nullable?