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

Add better collection stubs #547

Merged
merged 2 commits into from
Apr 28, 2020

Conversation

Daanra
Copy link
Contributor

@Daanra Daanra commented Apr 27, 2020

Adds better stubs for Collection methods such that Larastan understands them better.

Larastan will now understand that e.g. the following things are not valid:

User::all()->each(function (int $user, User $key): void { // Expects User as first parameter and int as second

});

/**
  * @param EloquentCollection<User>
  * @return Collection<User>    // Collection<User> and Collection<string> mismatch
  */
public function getNames($items)
{
   return $items->map(function (User $user): string {
       return $user->name;
  });
}

@nunomaduro nunomaduro merged commit 565b568 into larastan:master Apr 28, 2020
@nunomaduro
Copy link
Collaborator

@Daanra Can you pull request an entry just bellow Unreleased on the changelog?

@canvural
Copy link
Collaborator

Thank you!

I updated the changelog and released 0.5.7 👍

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.

None yet

3 participants