1
- <?php namespace GeneaLabs \LaravelModelCaching \Traits ;
1
+ <?php
2
+
3
+ namespace GeneaLabs \LaravelModelCaching \Traits ;
2
4
3
5
use Closure ;
4
6
use GeneaLabs \LaravelModelCaching \CachedBuilder ;
@@ -45,15 +47,19 @@ public function applyScopes()
45
47
46
48
protected function applyScopesToInstance ()
47
49
{
48
- if (! property_exists ($ this , "scopes " )
50
+ if (
51
+ ! property_exists ($ this , "scopes " )
49
52
|| $ this ->scopesAreApplied
50
53
|| $ this ->withoutAllGlobalScopes
51
54
) {
52
55
return ;
53
56
}
54
57
55
58
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
+ ) {
57
63
continue ;
58
64
}
59
65
@@ -62,7 +68,8 @@ protected function applyScopesToInstance()
62
68
$ scope ($ this );
63
69
}
64
70
65
- if ($ scope instanceof Scope
71
+ if (
72
+ $ scope instanceof Scope
66
73
&& $ this instanceof CachedBuilder
67
74
) {
68
75
$ scope ->apply ($ this , $ this ->getModel ());
@@ -127,7 +134,8 @@ protected function getCachePrefix() : string
127
134
->make ("config " )
128
135
->get ("laravel-model-caching.cache-prefix " , "" );
129
136
130
- if ($ this ->model
137
+ if (
138
+ $ this ->model
131
139
&& property_exists ($ this ->model , "cachePrefix " )
132
140
) {
133
141
$ cachePrefix = $ this ->model ->cachePrefix ;
@@ -163,7 +171,8 @@ protected function makeCacheKey(
163
171
->make ("db " )
164
172
->query ();
165
173
166
- if ($ this ->query
174
+ if (
175
+ $ this ->query
167
176
&& method_exists ($ this ->query , "getQuery " )
168
177
) {
169
178
$ query = $ this ->query ->getQuery ();
@@ -230,7 +239,8 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance)
230
239
{
231
240
[$ cacheCooldown , $ invalidatedAt ] = $ this ->getModelCacheCooldown ($ instance );
232
241
233
- if (! $ cacheCooldown
242
+ if (
243
+ ! $ cacheCooldown
234
244
|| (new Carbon )->now ()->diffInSeconds ($ invalidatedAt ) < $ cacheCooldown
235
245
) {
236
246
return ;
@@ -287,22 +297,25 @@ public function isCachable() : bool
287
297
->get ("laravel-model-caching.enabled " );
288
298
$ allRelationshipsAreCachable = true ;
289
299
290
- if (property_exists ($ this , "eagerLoad " )
300
+ if (
301
+ property_exists ($ this , "eagerLoad " )
291
302
&& $ this ->eagerLoad
292
303
) {
293
304
$ allRelationshipsAreCachable = collect ($ this
294
305
->eagerLoad )
295
306
->keys ()
296
307
->reduce (function ($ carry , $ related ) {
297
- if (! method_exists ($ this ->model , $ related )
308
+ if (
309
+ ! method_exists ($ this ->model , $ related )
298
310
|| $ carry === false
299
311
) {
300
312
return $ carry ;
301
313
}
302
314
303
315
$ relatedModel = $ this ->model ->$ related ()->getRelated ();
304
316
305
- if (! method_exists ($ relatedModel , "isCachable " )
317
+ if (
318
+ ! method_exists ($ relatedModel , "isCachable " )
306
319
|| ! $ relatedModel ->isCachable ()
307
320
) {
308
321
return false ;
0 commit comments