Skip to content

Commit 3b03241

Browse files
committed
Brought tests back to green.
1 parent 7c4b047 commit 3b03241

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

Diff for: src/Traits/BuilderCaching.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace GeneaLabs\LaravelModelCaching\Traits;
1+
<?php
2+
3+
namespace GeneaLabs\LaravelModelCaching\Traits;
24

35
use Illuminate\Database\Eloquent\Collection;
46

@@ -31,15 +33,20 @@ public function withoutGlobalScope($scope)
3133

3234
public function withoutGlobalScopes(array $scopes = null)
3335
{
34-
if ($scopes != null) {
36+
if ($scopes !== null) {
3537
$this->withoutGlobalScopes = $scopes;
3638
}
3739

38-
if ($scopes == null || ($scopes != null && count($scopes) == 0)) {
40+
if (
41+
$scopes == null
42+
|| (
43+
$scopes !== null
44+
&& count($scopes) === 0
45+
)
46+
) {
3947
$this->withoutAllGlobalScopes = true;
4048
}
4149

4250
return parent::withoutGlobalScopes($scopes);
4351
}
44-
4552
}

Diff for: src/Traits/Caching.php

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace GeneaLabs\LaravelModelCaching\Traits;
1+
<?php
2+
3+
namespace GeneaLabs\LaravelModelCaching\Traits;
24

35
use Closure;
46
use GeneaLabs\LaravelModelCaching\CachedBuilder;
@@ -45,15 +47,19 @@ public function applyScopes()
4547

4648
protected function applyScopesToInstance()
4749
{
48-
if (! property_exists($this, "scopes")
50+
if (
51+
! property_exists($this, "scopes")
4952
|| $this->scopesAreApplied
5053
|| $this->withoutAllGlobalScopes
5154
) {
5255
return;
5356
}
5457

5558
foreach ($this->scopes as $identifier => $scope) {
56-
if (! isset($this->scopes[$identifier]) || isset($this->withoutGlobalScopes[$identifier])) {
59+
if (
60+
! isset($this->scopes[$identifier])
61+
|| isset($this->withoutGlobalScopes[$identifier])
62+
) {
5763
continue;
5864
}
5965

@@ -62,7 +68,8 @@ protected function applyScopesToInstance()
6268
$scope($this);
6369
}
6470

65-
if ($scope instanceof Scope
71+
if (
72+
$scope instanceof Scope
6673
&& $this instanceof CachedBuilder
6774
) {
6875
$scope->apply($this, $this->getModel());
@@ -127,7 +134,8 @@ protected function getCachePrefix() : string
127134
->make("config")
128135
->get("laravel-model-caching.cache-prefix", "");
129136

130-
if ($this->model
137+
if (
138+
$this->model
131139
&& property_exists($this->model, "cachePrefix")
132140
) {
133141
$cachePrefix = $this->model->cachePrefix;
@@ -163,7 +171,8 @@ protected function makeCacheKey(
163171
->make("db")
164172
->query();
165173

166-
if ($this->query
174+
if (
175+
$this->query
167176
&& method_exists($this->query, "getQuery")
168177
) {
169178
$query = $this->query->getQuery();
@@ -230,7 +239,8 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance)
230239
{
231240
[$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance);
232241

233-
if (! $cacheCooldown
242+
if (
243+
! $cacheCooldown
234244
|| (new Carbon)->now()->diffInSeconds($invalidatedAt) < $cacheCooldown
235245
) {
236246
return;
@@ -287,22 +297,25 @@ public function isCachable() : bool
287297
->get("laravel-model-caching.enabled");
288298
$allRelationshipsAreCachable = true;
289299

290-
if (property_exists($this, "eagerLoad")
300+
if (
301+
property_exists($this, "eagerLoad")
291302
&& $this->eagerLoad
292303
) {
293304
$allRelationshipsAreCachable = collect($this
294305
->eagerLoad)
295306
->keys()
296307
->reduce(function ($carry, $related) {
297-
if (! method_exists($this->model, $related)
308+
if (
309+
! method_exists($this->model, $related)
298310
|| $carry === false
299311
) {
300312
return $carry;
301313
}
302314

303315
$relatedModel = $this->model->$related()->getRelated();
304316

305-
if (! method_exists($relatedModel, "isCachable")
317+
if (
318+
! method_exists($relatedModel, "isCachable")
306319
|| ! $relatedModel->isCachable()
307320
) {
308321
return false;

Diff for: tests/Integration/CachedBuilder/UpdateRelationTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
1+
<?php
2+
3+
namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
24

35
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
46
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;

0 commit comments

Comments
 (0)