driftingly / rector-laravel

Rector upgrades rules for Laravel
http://getrector.org
MIT License
540 stars 52 forks source link

AddGenericReturnTypeToRelationsRector not compliant with updated relation generic #259

Open joostdebruijn opened 17 hours ago

joostdebruijn commented 17 hours ago

In both Laravel (https://github.com/laravel/framework/pull/51851) as Larastan (https://github.com/larastan/larastan/pull/1990), the relation generics have been updated. Running the AddGenericReturnTypeToRelationsRector doesn't add the generic return types correctly anymore and even suggests to remove the correct ones. For example:

     /**
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\Post, $this>
+     * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\Post>
      */
     public function posts(): HasMany
     {
          //
     }

I had a look at the implementation of the Rector rule but as of now I'm not confident enough how to fix the rule in the right way.

canvural commented 8 hours ago

oh, I'm actually working on this. If someone else does not beat me to it, I'll create a PR.

GeniJaho commented 8 hours ago

@canvural if you mean you're working on a PR on this repository, it's always welcome. 😄

canvural commented 8 hours ago

@canvural if you mean you're working on a PR on this repository, it's always welcome. 😄

Yeah exactly. But we'll need to convert it to configurable rule because we need to support both <Laravel11.15 and up.