You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling unique() on an Eloquent Collection (or a custom Collection class), the return type is inferred as Illuminate\\Support\\Collection, however, this is incorrect.
Laravel's PHPDoc seems to be correct, and it doesn't seem like we're overriding it with a stub. So I'm unsure why this is happening.
Method Tests\\Features\\ReturnTypes\\CustomEloquentCollectionTest::testCollectionUnique() should return Illuminate\\Database\\Eloquent\\Collection but returns Illuminate\\Support\\Collection.
The text was updated successfully, but these errors were encountered:
I think the return type in Laravel is wrong. It should be just static There is no need for union. Changing it to just static makes your test case pass.
Edit: I think PHPStan normalizes the type static|\Illuminate\Support\Collection to \Illuminate\Support\Collection because it's the parent class.
But I couldn't figure out in which cases can it return Support/Collection instead of Eloquent/Collection Do you have any example?
Edit: I think PHPStan normalizes the type static|\Illuminate\Support\Collection to \Illuminate\Support\Collection because it's the parent class.
Thanks for pointing me in the right direction, I wasn't aware of this. This is kind of weird though. static|\Illuminate\Support\Collection is a perfectly valid type and is definitely not equivalent to just \Illuminate\Support\Collection. Anyhow, this is more a PHPStan problem.
The unique return type was indeed incorrect, so I fixed it here.
--level
used: maxDescription
When calling
unique()
on an Eloquent Collection (or a custom Collection class), the return type is inferred asIlluminate\\Support\\Collection
, however, this is incorrect.Laravel's PHPDoc seems to be correct, and it doesn't seem like we're overriding it with a stub. So I'm unsure why this is happening.
Laravel code where the issue was found
Error output:
The text was updated successfully, but these errors were encountered: