laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Relation method with union return type

Open megawubs opened this issue 1 year ago • 0 comments

Versions:

  • ide-helper Version: 2.12.3
  • Laravel Version: 8.83.23
  • PHP Version: 8.0.21

Description:

Relation methods that have a union return type will not be added as @property-read doc blocs.

User.php

    // ... 
    public function sentMessages(): HasMany|MessageQueryBuilder
    {
        return $this->messages()->sent();
    }
    // ... 

Message.php

    // ... 
    public function newEloquentBuilder($query): MessageQueryBuilder
    {
        return new MessageQueryBuilder($query);
    }
    // ... 

MessageQueryBuilder.php

    // ... 
    public function sent(): self
    {
        return $this->whereNotNull('sent_at');
    }
    // ...

Steps To Reproduce:

  • See code example above
  • Create a model with it's own EloquentQueryBuilder, This is MessageQueryBuilder for the Message model in my example
  • Use this builder for a union return type on a relation on another model that has a relation with Message. In my example this is the User model.
  • Run php artisan ide-helper:models -W -r
  • The $sentMessages property is not added to the docblock

The order of the union return type does not matter: HasMany|MessageQueryBuilder as well als MessageQueryBuilder|HasMany does not work.

megawubs avatar Sep 13 '22 07:09 megawubs