Skip to content

Commit

Permalink
Merge pull request #41339 from netpok/fix-collection-typehints
Browse files Browse the repository at this point in the history
[9.x] Fix collection typehint templates
  • Loading branch information
nunomaduro authored Mar 4, 2022
2 parents 04e4edc + c638533 commit ee2958b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function diff($items)
* Get the items in the collection that are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @param callable(TValue): int $callback
* @param callable(TValue, TValue): int $callback
* @return static
*/
public function diffUsing($items, callable $callback)
Expand All @@ -254,7 +254,7 @@ public function diffAssoc($items)
* Get the items in the collection whose keys and values are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey): int $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffAssocUsing($items, callable $callback)
Expand All @@ -277,7 +277,7 @@ public function diffKeys($items)
* Get the items in the collection whose keys are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey): int $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffKeysUsing($items, callable $callback)
Expand Down Expand Up @@ -1436,7 +1436,7 @@ public function sortKeysDesc($options = SORT_REGULAR)
/**
* Sort the collection keys using a callback.
*
* @param callable $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function sortKeysUsing(callable $callback)
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function diff($items);
* Get the items that are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @param callable(TValue): int $callback
* @param callable(TValue, TValue): int $callback
* @return static
*/
public function diffUsing($items, callable $callback);
Expand All @@ -217,7 +217,7 @@ public function diffAssoc($items);
* Get the items whose keys and values are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey): int $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffAssocUsing($items, callable $callback);
Expand All @@ -234,7 +234,7 @@ public function diffKeys($items);
* Get the items whose keys are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey): int $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffKeysUsing($items, callable $callback);
Expand Down Expand Up @@ -1016,7 +1016,7 @@ public function sortKeysDesc($options = SORT_REGULAR);
/**
* Sort the collection keys using a callback.
*
* @param callable $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function sortKeysUsing(callable $callback);
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function diff($items)
* Get the items that are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @param callable(TValue): int $callback
* @param callable(TValue, TValue): int $callback
* @return static
*/
public function diffUsing($items, callable $callback)
Expand All @@ -330,7 +330,7 @@ public function diffAssoc($items)
* Get the items whose keys and values are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey): int $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffAssocUsing($items, callable $callback)
Expand All @@ -353,7 +353,7 @@ public function diffKeys($items)
* Get the items whose keys are not present in the given items, using the callback.
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey): int $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffKeysUsing($items, callable $callback)
Expand Down Expand Up @@ -1344,7 +1344,7 @@ public function sortKeysDesc($options = SORT_REGULAR)
/**
* Sort the collection keys using a callback.
*
* @param callable $callback
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function sortKeysUsing(callable $callback)
Expand Down
30 changes: 18 additions & 12 deletions types/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,41 +137,47 @@ public function __invoke(): string
assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diff([1, 2]));
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diff(['string-2']));

assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffUsing([1, 2], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffUsing([1, 2], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diffUsing(['string-2'], function ($string) {
assertType('string', $string);
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diffUsing(['string-2'], function ($stringA, $stringB) {
assertType('string', $stringA);
assertType('string', $stringB);

return -1;
}));

assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffAssoc([1, 2]));
assertType('Illuminate\Support\Collection<string, string>', $collection::make(['string' => 'string'])->diffAssoc(['string' => 'string']));

assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffAssocUsing([1, 2], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffAssocUsing([1, 2], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diffAssocUsing(['string-2'], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diffAssocUsing(['string-2'], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));

assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffKeys([1, 2]));
assertType('Illuminate\Support\Collection<string, string>', $collection::make(['string' => 'string'])->diffKeys(['string' => 'string']));

assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffKeysUsing([1, 2], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\Collection<int, int>', $collection::make([3, 4])->diffKeysUsing([1, 2], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diffKeysUsing(['string-2'], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\Collection<int, string>', $collection::make(['string-1'])->diffKeysUsing(['string-2'], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
Expand Down
30 changes: 18 additions & 12 deletions types/Support/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,41 +127,47 @@
assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diff([1, 2]));
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diff(['string-2']));

assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffUsing([1, 2], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffUsing([1, 2], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diffUsing(['string-2'], function ($string) {
assertType('string', $string);
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diffUsing(['string-2'], function ($stringA, $stringB) {
assertType('string', $stringA);
assertType('string', $stringB);

return -1;
}));

assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffAssoc([1, 2]));
assertType('Illuminate\Support\LazyCollection<string, string>', $collection::make(['string' => 'string'])->diffAssoc(['string' => 'string']));

assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffAssocUsing([1, 2], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffAssocUsing([1, 2], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diffAssocUsing(['string-2'], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diffAssocUsing(['string-2'], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));

assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffKeys([1, 2]));
assertType('Illuminate\Support\LazyCollection<string, string>', $collection::make(['string' => 'string'])->diffKeys(['string' => 'string']));

assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffKeysUsing([1, 2], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\LazyCollection<int, int>', $collection::make([3, 4])->diffKeysUsing([1, 2], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diffKeysUsing(['string-2'], function ($int) {
assertType('int', $int);
assertType('Illuminate\Support\LazyCollection<int, string>', $collection::make(['string-1'])->diffKeysUsing(['string-2'], function ($intA, $intB) {
assertType('int', $intA);
assertType('int', $intB);

return -1;
}));
Expand Down

0 comments on commit ee2958b

Please sign in to comment.