fix: add return types for cache implementations

Fixes the following message reported by `symfony/error-handler`:

`User Deprecated: Method "Psr\SimpleCache\CacheInterface::get()" might
add "mixed" as a native return type declaration in the future. Do the
same in implementation "CuyZ\Valinor\Cache\..." now to avoid errors or
add an explicit @return annotation to suppress this message.`
This commit is contained in:
Lukáš Unger 2022-09-24 19:29:02 +02:00 committed by GitHub
parent d8957c061d
commit 0e8f12e5f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 0 deletions

View File

@ -29,6 +29,11 @@ final class ChainCache implements CacheInterface
$this->count = count($caches);
}
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return EntryType|null
*/
public function get($key, $default = null)
{
foreach ($this->delegates as $i => $delegate) {

View File

@ -62,6 +62,11 @@ final class CompiledPhpFileCache implements CacheInterface
return $this->getFile($filename)->isValid();
}
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return EntryType|null
*/
public function get($key, $default = null)
{
if (! $this->has($key)) {

View File

@ -51,6 +51,11 @@ final class FileSystemCache implements CacheInterface
return false;
}
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return EntryType|null
*/
public function get($key, $default = null)
{
foreach ($this->delegates as $delegate) {

View File

@ -57,6 +57,11 @@ final class FileWatchingCache implements CacheInterface
return $this->delegate->has($key);
}
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return EntryType|TimestampsArray|null
*/
public function get($key, $default = null)
{
return $this->delegate->get($key, $default);

View File

@ -43,6 +43,11 @@ final class KeySanitizerCache implements CacheInterface
$this->sanitize = static fn (string $key) => sha1("$key." . self::$version ??= PHP_VERSION . '/' . Package::version());
}
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return EntryType|null
*/
public function get($key, $default = null)
{
return $this->delegate->get(($this->sanitize)($key), $default);

View File

@ -24,6 +24,11 @@ final class RuntimeCache implements CacheInterface
/** @var array<string, EntryType> */
private array $entries = [];
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return EntryType|null
*/
public function get($key, $default = null)
{
return $this->entries[$key] ?? $default;

View File

@ -44,6 +44,11 @@ final class FakeCache implements CacheInterface
return count($this->entries);
}
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return mixed
*/
public function get($key, $default = null)
{
$this->timesEntryWasFetched[$key] ??= 0;

View File

@ -11,6 +11,11 @@ use Psr\SimpleCache\CacheInterface;
*/
final class FakeFailingCache implements CacheInterface
{
/**
* @PHP8.0 add `mixed` return type and remove PHPDoc
*
* @return mixed
*/
public function get($key, $default = null)
{
return null;