PhpStan error on $this->resolveRecord($record)

Hello All, I run phpstan on my code regularly, and I stumbled upon the following issue. This code excerpt is from a page definition
class PosMenuPage extends Page{
...
/**
* @var PointOfSale|int|string|null
*/
public Model|string|int|null $record;

public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
$this->categories = $this->record->merchant->categories()
...
class PosMenuPage extends Page{
...
/**
* @var PointOfSale|int|string|null
*/
public Model|string|int|null $record;

public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
$this->categories = $this->record->merchant->categories()
...
Phpstan reports the following for the last row:
Access to an undefined property Illuminate\Database\Eloquent\Model::$merchant.
Even I declared the $record type in the docblock, the resolveRecord return type is a Model, and phpstan can't recognize the merchant belongsTo relation. Of course I can re-implement the resolveRecord function in my class and typehint with the correct return type, but I feel this is just add unnecessary bloat to my code. How can I typehint this function to pass the phpstan?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server