From a99fcbdd1618e9e2a7e8d95ca527cdedc1c81b3f Mon Sep 17 00:00:00 2001 From: Niclas van Eyk Date: Wed, 9 Feb 2022 22:49:11 +0100 Subject: [PATCH 1/3] Widen the type of Collection::unique $key parameter This was narrowed down to bool, but the docs and implementation actually support arbitrary values. --- src/Illuminate/Collections/Collection.php | 2 +- src/Illuminate/Collections/Enumerable.php | 4 ++-- src/Illuminate/Collections/LazyCollection.php | 2 +- src/Illuminate/Collections/Traits/EnumeratesValues.php | 4 ++-- src/Illuminate/Database/Eloquent/Collection.php | 2 +- types/Database/Eloquent/Collection.php | 2 +- types/Support/Collection.php | 8 ++++---- types/Support/LazyCollection.php | 8 ++++---- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index b247bf84bdd6..3fda5a3567cb 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -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 */ diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index 0ad48def0f7d..c0ba789c8742 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -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 */ @@ -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); diff --git a/src/Illuminate/Collections/LazyCollection.php b/src/Illuminate/Collections/LazyCollection.php index 89f1417127e8..3fb672a5bbd9 100644 --- a/src/Illuminate/Collections/LazyCollection.php +++ b/src/Illuminate/Collections/LazyCollection.php @@ -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 */ diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index 7a48c0a80e69..4dd07ea9de11 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -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 */ @@ -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) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 93fab46efc5c..58100873377a 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -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 */ diff --git a/types/Database/Eloquent/Collection.php b/types/Database/Eloquent/Collection.php index 30609f5cc0ba..3232c0d10c7f 100644 --- a/types/Database/Eloquent/Collection.php +++ b/types/Database/Eloquent/Collection.php @@ -135,7 +135,7 @@ assertType('User', $user); assertType('int', $int); - return true; + return $user->id; })); assertType('Illuminate\Database\Eloquent\Collection', $collection->unique('string')); diff --git a/types/Support/Collection.php b/types/Support/Collection.php index e4603d1d6e37..5a3a9fa057db 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -747,13 +747,13 @@ assertType('User', $user); assertType('int', $int); - return true; + return $user->id; })); assertType('Illuminate\Support\Collection', $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', $collection->uniqueStrict()); @@ -761,7 +761,7 @@ assertType('User', $user); assertType('int', $int); - return true; + return $user->id; })); assertType('Illuminate\Support\Collection', $collection->values()); diff --git a/types/Support/LazyCollection.php b/types/Support/LazyCollection.php index 83010a1deed1..5b3b5767b99c 100644 --- a/types/Support/LazyCollection.php +++ b/types/Support/LazyCollection.php @@ -745,13 +745,13 @@ assertType('User', $user); assertType('int', $int); - return true; + return $user->id; })); assertType('Illuminate\Support\LazyCollection', $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', $collection->uniqueStrict()); @@ -759,7 +759,7 @@ assertType('User', $user); assertType('int', $int); - return true; + return $user->id; })); assertType('Illuminate\Support\LazyCollection', $collection->values()); From ed70b724bd1d10230465bf5c8ae5453f5be40949 Mon Sep 17 00:00:00 2001 From: Niclas van Eyk Date: Wed, 9 Feb 2022 23:00:34 +0100 Subject: [PATCH 2/3] fix non-existing property --- types/Database/Eloquent/Collection.php | 2 +- types/Support/Collection.php | 4 ++-- types/Support/LazyCollection.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/Database/Eloquent/Collection.php b/types/Database/Eloquent/Collection.php index 3232c0d10c7f..bc7e85a2c31a 100644 --- a/types/Database/Eloquent/Collection.php +++ b/types/Database/Eloquent/Collection.php @@ -135,7 +135,7 @@ assertType('User', $user); assertType('int', $int); - return $user->id; + return $user->primaryKey; })); assertType('Illuminate\Database\Eloquent\Collection', $collection->unique('string')); diff --git a/types/Support/Collection.php b/types/Support/Collection.php index 5a3a9fa057db..48f7775fbd48 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -747,7 +747,7 @@ assertType('User', $user); assertType('int', $int); - return $user->id; + return $user->primaryKey; })); assertType('Illuminate\Support\Collection', $collection->make(['string' => 'string'])->unique(function ($stringA, $stringB) { assertType('string', $stringA); @@ -761,7 +761,7 @@ assertType('User', $user); assertType('int', $int); - return $user->id; + return $user->primaryKey; })); assertType('Illuminate\Support\Collection', $collection->values()); diff --git a/types/Support/LazyCollection.php b/types/Support/LazyCollection.php index 5b3b5767b99c..9a487317ab7e 100644 --- a/types/Support/LazyCollection.php +++ b/types/Support/LazyCollection.php @@ -745,7 +745,7 @@ assertType('User', $user); assertType('int', $int); - return $user->id; + return $user->primaryKey; })); assertType('Illuminate\Support\LazyCollection', $collection->make(['string' => 'string'])->unique(function ($stringA, $stringB) { assertType('string', $stringA); @@ -759,7 +759,7 @@ assertType('User', $user); assertType('int', $int); - return $user->id; + return $user->primaryKey; })); assertType('Illuminate\Support\LazyCollection', $collection->values()); From c2ed804419863bac44904a377311808677c4588f Mon Sep 17 00:00:00 2001 From: Niclas van Eyk Date: Wed, 9 Feb 2022 23:05:00 +0100 Subject: [PATCH 3/3] fix type tests again --- types/Database/Eloquent/Collection.php | 2 +- types/Support/Collection.php | 4 ++-- types/Support/LazyCollection.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/Database/Eloquent/Collection.php b/types/Database/Eloquent/Collection.php index bc7e85a2c31a..6d0ef52da49f 100644 --- a/types/Database/Eloquent/Collection.php +++ b/types/Database/Eloquent/Collection.php @@ -135,7 +135,7 @@ assertType('User', $user); assertType('int', $int); - return $user->primaryKey; + return $user->getTable(); })); assertType('Illuminate\Database\Eloquent\Collection', $collection->unique('string')); diff --git a/types/Support/Collection.php b/types/Support/Collection.php index 48f7775fbd48..7393da1c1d93 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -747,7 +747,7 @@ assertType('User', $user); assertType('int', $int); - return $user->primaryKey; + return $user->getTable(); })); assertType('Illuminate\Support\Collection', $collection->make(['string' => 'string'])->unique(function ($stringA, $stringB) { assertType('string', $stringA); @@ -761,7 +761,7 @@ assertType('User', $user); assertType('int', $int); - return $user->primaryKey; + return $user->getTable(); })); assertType('Illuminate\Support\Collection', $collection->values()); diff --git a/types/Support/LazyCollection.php b/types/Support/LazyCollection.php index 9a487317ab7e..621d2e375cb1 100644 --- a/types/Support/LazyCollection.php +++ b/types/Support/LazyCollection.php @@ -745,7 +745,7 @@ assertType('User', $user); assertType('int', $int); - return $user->primaryKey; + return $user->getTable(); })); assertType('Illuminate\Support\LazyCollection', $collection->make(['string' => 'string'])->unique(function ($stringA, $stringB) { assertType('string', $stringA); @@ -759,7 +759,7 @@ assertType('User', $user); assertType('int', $int); - return $user->primaryKey; + return $user->getTable(); })); assertType('Illuminate\Support\LazyCollection', $collection->values());