Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Collection::flatMap callback can return Enumerable #970

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

bastien-phi
Copy link
Contributor

@bastien-phi bastien-phi commented Oct 18, 2021

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

Fixes #969

Changes

This PR allows PHPStan to resolve TReturn when flatMap is called with a callback returning an Enumerable.

For exemple, before this PR:

$users = User::all();
$accounts = $users->flatMap(fn(User $user) => $user->accounts);

fails with

Unable to resolve the template type TReturn
in call to method Illuminate\Support\Collection<int,App\Model\User>::flatMap()

After this PR, $accounts is successfully resolved as lluminate\Support\Collection<int,App\Model\Account>.

@szepeviktor
Copy link
Collaborator

Thank you!

Copy link
Collaborator

@canvural canvural left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I just added one feedback regarding the test case.

tests/Features/ReturnTypes/CollectionStub.php Outdated Show resolved Hide resolved
@bastien-phi
Copy link
Contributor Author

Is it better this way ?

@canvural canvural changed the title Collection::flatMap callback can return Enumerable fix: Collection::flatMap callback can return Enumerable Oct 18, 2021
@canvural canvural merged commit d4766ed into larastan:master Oct 18, 2021
@canvural
Copy link
Collaborator

Thank you!

@bastien-phi
Copy link
Contributor Author

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Callback given to Collection::flatMap should be allowed to return a Collection
3 participants