Skip to content

Commit

Permalink
Fix: Correct typehint on repository retrieval methods (#53025)
Browse files Browse the repository at this point in the history
* widen typehint on repository get

* replace Closure(): mixed with mixed

* fix type tests
  • Loading branch information
liamduckett authored Oct 7, 2024
1 parent 5caf767 commit 6df8b61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 4 additions & 8 deletions src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ public function missing($key)
/**
* Retrieve an item from the cache by key.
*
* @template TCacheValue
*
* @param array|string $key
* @param TCacheValue|(\Closure(): TCacheValue) $default
* @return (TCacheValue is null ? mixed : TCacheValue)
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null): mixed
{
Expand Down Expand Up @@ -198,11 +196,9 @@ protected function handleManyResult($keys, $key, $value)
/**
* Retrieve an item from the cache and delete it.
*
* @template TCacheValue
*
* @param array|string $key
* @param TCacheValue|(\Closure(): TCacheValue) $default
* @return (TCacheValue is null ? mixed : TCacheValue)
* @param mixed $default
* @return mixed
*/
public function pull($key, $default = null)
{
Expand Down
8 changes: 4 additions & 4 deletions types/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
$cache = resolve(Repository::class);

assertType('mixed', $cache->get('key'));
assertType('int', $cache->get('cache', 27));
assertType('int', $cache->get('cache', function (): int {
assertType('mixed', $cache->get('cache', 27));
assertType('mixed', $cache->get('cache', function (): int {
return 26;
}));

assertType('mixed', $cache->pull('key'));
assertType('int', $cache->pull('cache', 28));
assertType('int', $cache->pull('cache', function (): int {
assertType('mixed', $cache->pull('cache', 28));
assertType('mixed', $cache->pull('cache', function (): int {
return 30;
}));
assertType('int', $cache->sear('cache', function (): int {
Expand Down

0 comments on commit 6df8b61

Please sign in to comment.