Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed deprecations to work with PHP 8.2 #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Contracts/QueryCacheModuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion src/FlushQueryCacheObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Rennokki\QueryCache;

use Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

class FlushQueryCacheObserver
Expand Down Expand Up @@ -150,7 +151,7 @@ public function morphToManyUpdatedExistingPivot($relation, Model $model, $ids)
*
* @throws Exception
*/
protected function invalidateCache(Model $model, $relation = null, $pivotedModels = null): void
protected function invalidateCache(Model $model, $relation = null, ?Collection $pivotedModels = null): void
{
$class = get_class($model);

Expand Down
10 changes: 5 additions & 5 deletions src/Traits/QueryCacheModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -147,7 +147,7 @@ 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();

Expand Down
3 changes: 2 additions & 1 deletion src/Traits/QueryCacheable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rennokki\QueryCache\Traits;

use Illuminate\Database\Eloquent\Collection;
use Rennokki\QueryCache\FlushQueryCacheObserver;
use Rennokki\QueryCache\Query\Builder;

Expand Down Expand Up @@ -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($relation = null, ?Collection $pivotedModels = null): array
{
/** @var \Illuminate\Database\Eloquent\Model $this */
return $this->getCacheBaseTags();
Expand Down
3 changes: 2 additions & 1 deletion tests/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Chelout\RelationshipEvents\Concerns\HasBelongsToManyEvents;
use Chelout\RelationshipEvents\Traits\HasRelationshipObservables;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Rennokki\QueryCache\Traits\QueryCacheable;

Expand Down Expand Up @@ -42,7 +43,7 @@ protected function cacheForValue()
return 3600;
}

public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array
public function getCacheTagsToInvalidateOnUpdate($relation = null, ?Collection $pivotedModels = null): array
{
if ($relation === 'roles') {
$tags = array_reduce($pivotedModels->all(), function ($tags, Role $role) {
Expand Down
7 changes: 5 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public function setUp(): void
{
parent::setUp();

if ($this->getProvidedData() && method_exists(Model::class, 'preventAccessingMissingAttributes')) {
if (method_exists($this, 'getProvidedData')
&& $this->getProvidedData()
&& method_exists(Model::class, 'preventAccessingMissingAttributes')
) {
[$strict] = $this->getProvidedData();
Model::preventAccessingMissingAttributes($strict);
}
Expand Down Expand Up @@ -99,7 +102,7 @@ protected function clearCache()
* @param array|null $tags
* @return mixed
*/
protected function getCacheWithTags(string $key, $tags = null)
protected function getCacheWithTags(string $key, ?array $tags = null)
{
return $this->driverSupportsTags()
? Cache::tags($tags)->get($key)
Expand Down
Loading