Skip to content

Commit

Permalink
Merge pull request #40903 from NiclasvanEyk/widen-unique-key-types
Browse files Browse the repository at this point in the history
[9.x] Widen the type of `Collection::unique` `$key` parameter
  • Loading branch information
nunomaduro authored Feb 10, 2022
2 parents 039cde6 + c2ed804 commit e76a1ec
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
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

0 comments on commit e76a1ec

Please sign in to comment.