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

[9.x] Widen the type of Collection::unique $key parameter #40903

Merged
merged 3 commits into from
Feb 10, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ public function undot()
/**
* Return only unique items from the collection array.
*
* @param (callable(TValue, TKey): bool)|string|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ public function undot();
/**
* Return only unique items from the collection array.
*
* @param (callable(TValue, TKey): bool)|string|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
Expand All @@ -1123,7 +1123,7 @@ public function unique($key = null, $strict = false);
/**
* Return only unique items from the collection array using strict comparison.
*
* @param (callable(TValue, TKey): bool)|string|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @return static
*/
public function uniqueStrict($key = null);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ public function undot()
/**
* Return only unique items from the collection array.
*
* @param (callable(TValue, TKey): bool)|string|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ public function tap(callable $callback)
/**
* Return only unique items from the collection array.
*
* @param (callable(TValue, TKey): bool)|string|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
Expand All @@ -840,7 +840,7 @@ public function unique($key = null, $strict = false)
/**
* Return only unique items from the collection array using strict comparison.
*
* @param (callable(TValue, TKey): bool)|string|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @return static
*/
public function uniqueStrict($key = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public function intersect($items)
/**
* Return only unique items from the collection.
*
* @param (callable(TModel, TKey): bool)|string|null $key
* @param (callable(TModel, TKey): mixed)|string|null $key
* @param bool $strict
* @return static<int, TModel>
*/
Expand Down
2 changes: 1 addition & 1 deletion types/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
assertType('User', $user);
assertType('int', $int);

return true;
return $user->getTable();
}));
assertType('Illuminate\Database\Eloquent\Collection<int, User>', $collection->unique('string'));

Expand Down
8 changes: 4 additions & 4 deletions types/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,21 +747,21 @@
assertType('User', $user);
assertType('int', $int);

return true;
return $user->getTable();
}));
assertType('Illuminate\Support\Collection<string, string>', $collection->make(['string' => 'string'])->unique(function ($stringA, $stringB) {
assertType('string', $stringA);
assertType('string', $stringA);
assertType('string', $stringB);

return false;
return $stringA;
}, true));

assertType('Illuminate\Support\Collection<int, User>', $collection->uniqueStrict());
assertType('Illuminate\Support\Collection<int, User>', $collection->uniqueStrict(function ($user, $int) {
assertType('User', $user);
assertType('int', $int);

return true;
return $user->getTable();
}));

assertType('Illuminate\Support\Collection<int, User>', $collection->values());
Expand Down
8 changes: 4 additions & 4 deletions types/Support/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,21 +745,21 @@
assertType('User', $user);
assertType('int', $int);

return true;
return $user->getTable();
}));
assertType('Illuminate\Support\LazyCollection<string, string>', $collection->make(['string' => 'string'])->unique(function ($stringA, $stringB) {
assertType('string', $stringA);
assertType('string', $stringA);
assertType('string', $stringB);

return false;
return $stringA;
}, true));

assertType('Illuminate\Support\LazyCollection<int, User>', $collection->uniqueStrict());
assertType('Illuminate\Support\LazyCollection<int, User>', $collection->uniqueStrict(function ($user, $int) {
assertType('User', $user);
assertType('int', $int);

return true;
return $user->getTable();
}));

assertType('Illuminate\Support\LazyCollection<int, User>', $collection->values());
Expand Down