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 toArray and keyBy stubs #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions stubs/illuminate.support.collection.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ class Collection implements ArrayAccess, Enumerable
{
}

/**
* @template TCallbackReturn
*
* @param callable(TValue):TCallbackReturn $keyBy
*
* @return Collection<TCallbackReturn,TValue>
*/
public function keyBy($keyBy)
{
}

/**
* @return Collection<int,TKey>
*/
Expand Down Expand Up @@ -405,6 +416,13 @@ class Collection implements ArrayAccess, Enumerable
{
}

/**
* @return array<TKey,TValue>
*/
public function toArray()
{
}

/**
* @template TCallbackReturn
* @param Closure(TValue,?TKey):TCallbackReturn $callback
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance/IlluminateSupportCollection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Feature: Collections
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidScalarArgument | Argument 1 of Illuminate\Support\Collection::add expects bool, int(1) provided |
| InvalidScalarArgument | Argument 1 of Illuminate\Support\Collection::add expects bool, 1 provided |
And I see no other errors

@Collection::times
Expand All @@ -55,6 +55,7 @@ Feature: Collections
"""
/** @var Collection<string,string> */
$c = new Collection(['a' => 'A', 'b' => 'B', 'c' => 'C']);
/** @psalm-suppress UnusedMethodCall */
$c->all()[1];
"""
When I run Psalm
Expand All @@ -69,6 +70,7 @@ Feature: Collections
"""
/** @var Collection<string,string> */
$c = new Collection(['a' => 'A', 'b' => 'B', 'c' => 'C']);
/** @psalm-suppress UnusedMethodCall */
$c->all()['a'];
"""
When I run Psalm
Expand All @@ -85,7 +87,7 @@ Feature: Collections
When I run Psalm
Then I see these errors
| Type | Message |
| InvalidScalarArgument | Argument 1 of Illuminate\Support\Collection::add expects string, int(1) provided |
| InvalidScalarArgument | Argument 1 of Illuminate\Support\Collection::add expects string, 1 provided |
And I see no other errors

@Collection::add
Expand Down