From 85c0475741ff7b0bcef26dd1a2feb76400967766 Mon Sep 17 00:00:00 2001 From: eribys Date: Thu, 3 Apr 2025 06:07:23 +0000 Subject: [PATCH 1/3] fix deprecation messages --- src/Contracts/QueryCacheModuleInterface.php | 4 ++-- src/Traits/QueryCacheModule.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Contracts/QueryCacheModuleInterface.php b/src/Contracts/QueryCacheModuleInterface.php index 78a7f0d..0458986 100644 --- a/src/Contracts/QueryCacheModuleInterface.php +++ b/src/Contracts/QueryCacheModuleInterface.php @@ -12,7 +12,7 @@ interface QueryCacheModuleInterface * @param string|null $appends * @return string */ - public function generatePlainCacheKey(string $method = 'get', string $id = null, string $appends = null): string; + public function generatePlainCacheKey(string $method = 'get', ?string $id = null, ?string $appends = null): string; /** * Get the query cache callback. @@ -22,5 +22,5 @@ public function generatePlainCacheKey(string $method = 'get', string $id = null, * @param string|null $id * @return \Closure */ - public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], string $id = null); + public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], ?string $id = null); } diff --git a/src/Traits/QueryCacheModule.php b/src/Traits/QueryCacheModule.php index 79caa36..ed474e8 100644 --- a/src/Traits/QueryCacheModule.php +++ b/src/Traits/QueryCacheModule.php @@ -69,7 +69,7 @@ trait QueryCacheModule * @param string|null $id * @return array */ - public function getFromQueryCache(string $method = 'get', array $columns = ['*'], string $id = null) + public function getFromQueryCache(string $method = 'get', array $columns = ['*'], ?string $id = null) { if (is_null($this->columns)) { $this->columns = $columns; @@ -112,7 +112,7 @@ public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], * @param string|null $appends * @return string */ - public function getCacheKey(string $method = 'get', string $id = null, string $appends = null): string + public function getCacheKey(string $method = 'get', ?string $id = null, ?string $appends = null): string { $key = $this->generateCacheKey($method, $id, $appends); $prefix = $this->getCachePrefix(); @@ -128,7 +128,7 @@ public function getCacheKey(string $method = 'get', string $id = null, string $a * @param string|null $appends * @return string */ - public function generateCacheKey(string $method = 'get', string $id = null, string $appends = null): string + public function generateCacheKey(string $method = 'get', ?string $id = null, ?string $appends = null): string { $key = $this->generatePlainCacheKey($method, $id, $appends); @@ -147,16 +147,16 @@ public function generateCacheKey(string $method = 'get', string $id = null, stri * @param string|null $appends * @return string */ - public function generatePlainCacheKey(string $method = 'get', string $id = null, string $appends = null): string + public function generatePlainCacheKey(string $method = 'get', ?string $id = null, ?string $appends = null): string { $name = $this->connection->getName(); // Count has no Sql, that's why it can't be used ->toSql() if ($method === 'count') { - return $name.$method.$id.serialize($this->getBindings()).$appends; + return $name . $method . $id . serialize($this->getBindings()) . $appends; } - return $name.$method.$id.$this->toSql().serialize($this->getBindings()).$appends; + return $name . $method . $id . $this->toSql() . serialize($this->getBindings()) . $appends; } /** From d58d0c4f15706e647b720787f66e08fe4a72d1f0 Mon Sep 17 00:00:00 2001 From: eribys Date: Thu, 3 Apr 2025 06:15:33 +0000 Subject: [PATCH 2/3] add missing types based on function summaries --- src/FlushQueryCacheObserver.php | 5 +++-- src/Traits/QueryCacheModule.php | 2 +- src/Traits/QueryCacheable.php | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/FlushQueryCacheObserver.php b/src/FlushQueryCacheObserver.php index 7ca7ce2..48dc0bb 100644 --- a/src/FlushQueryCacheObserver.php +++ b/src/FlushQueryCacheObserver.php @@ -3,6 +3,7 @@ namespace Rennokki\QueryCache; use Exception; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; class FlushQueryCacheObserver @@ -150,14 +151,14 @@ public function morphToManyUpdatedExistingPivot($relation, Model $model, $ids) * * @throws Exception */ - protected function invalidateCache(Model $model, $relation = null, $pivotedModels = null): void + protected function invalidateCache(Model $model, ?string $relation = null, ?Collection $pivotedModels = null): void { $class = get_class($model); $tags = $model->getCacheTagsToInvalidateOnUpdate($relation, $pivotedModels); if (! $tags) { - throw new Exception('Automatic invalidation for '.$class.' works only if at least one tag to be invalidated is specified.'); + throw new Exception('Automatic invalidation for ' . $class . ' works only if at least one tag to be invalidated is specified.'); } $class::flushQueryCache($tags); diff --git a/src/Traits/QueryCacheModule.php b/src/Traits/QueryCacheModule.php index ed474e8..25959e9 100644 --- a/src/Traits/QueryCacheModule.php +++ b/src/Traits/QueryCacheModule.php @@ -95,7 +95,7 @@ public function getFromQueryCache(string $method = 'get', array $columns = ['*'] * @param string|null $id * @return \Closure */ - public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], string $id = null) + public function getQueryCacheCallback(string $method = 'get', $columns = ['*'], ?string $id = null) { return function () use ($method, $columns) { $this->avoidCache = true; diff --git a/src/Traits/QueryCacheable.php b/src/Traits/QueryCacheable.php index c9f85a8..91bb85d 100644 --- a/src/Traits/QueryCacheable.php +++ b/src/Traits/QueryCacheable.php @@ -2,6 +2,7 @@ namespace Rennokki\QueryCache\Traits; +use Illuminate\Database\Eloquent\Collection; use Rennokki\QueryCache\FlushQueryCacheObserver; use Rennokki\QueryCache\Query\Builder; @@ -68,7 +69,7 @@ protected function getCacheBaseTags(): array * @param \Illuminate\Database\Eloquent\Collection|null $pivotedModels * @return array */ - public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array + public function getCacheTagsToInvalidateOnUpdate(?string $relation = null, ?Collection $pivotedModels = null): array { /** @var \Illuminate\Database\Eloquent\Model $this */ return $this->getCacheBaseTags(); From 5825d8922e8774468c7d9e9a9b3a52f8ec2fda80 Mon Sep 17 00:00:00 2001 From: eribys Date: Thu, 3 Apr 2025 06:18:22 +0000 Subject: [PATCH 3/3] fix styleCI --- src/FlushQueryCacheObserver.php | 2 +- src/Traits/QueryCacheModule.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FlushQueryCacheObserver.php b/src/FlushQueryCacheObserver.php index 48dc0bb..f99cc43 100644 --- a/src/FlushQueryCacheObserver.php +++ b/src/FlushQueryCacheObserver.php @@ -158,7 +158,7 @@ protected function invalidateCache(Model $model, ?string $relation = null, ?Coll $tags = $model->getCacheTagsToInvalidateOnUpdate($relation, $pivotedModels); if (! $tags) { - throw new Exception('Automatic invalidation for ' . $class . ' works only if at least one tag to be invalidated is specified.'); + throw new Exception('Automatic invalidation for '.$class.' works only if at least one tag to be invalidated is specified.'); } $class::flushQueryCache($tags); diff --git a/src/Traits/QueryCacheModule.php b/src/Traits/QueryCacheModule.php index 25959e9..1eccc98 100644 --- a/src/Traits/QueryCacheModule.php +++ b/src/Traits/QueryCacheModule.php @@ -153,10 +153,10 @@ public function generatePlainCacheKey(string $method = 'get', ?string $id = null // Count has no Sql, that's why it can't be used ->toSql() if ($method === 'count') { - return $name . $method . $id . serialize($this->getBindings()) . $appends; + return $name.$method.$id.serialize($this->getBindings()).$appends; } - return $name . $method . $id . $this->toSql() . serialize($this->getBindings()) . $appends; + return $name.$method.$id.$this->toSql().serialize($this->getBindings()).$appends; } /**