@@ -6,7 +6,7 @@ |
||
6 | 6 | { |
7 | 7 | public function all($columns = ['*']) : Collection |
8 | 8 | { |
9 | - if (! $this->isCachable()) { |
|
9 | + if (!$this->isCachable()) { |
|
10 | 10 | $this->model->disableModelCaching(); |
11 | 11 | } |
12 | 12 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | { |
13 | 13 | $option = $this->option('model'); |
14 | 14 | |
15 | - if (! $option) { |
|
15 | + if (!$option) { |
|
16 | 16 | return $this->flushEntireCache(); |
17 | 17 | } |
18 | 18 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $usesCachableTrait = $this->getAllTraitsUsedByClass($option) |
37 | 37 | ->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable"); |
38 | 38 | |
39 | - if (! $usesCachableTrait) { |
|
39 | + if (!$usesCachableTrait) { |
|
40 | 40 | $this->error("'{$option}' is not an instance of CachedModel."); |
41 | 41 | $this->line("Only CachedModel instances can be flushed."); |
42 | 42 |
@@ -9,7 +9,7 @@ |
||
9 | 9 | |
10 | 10 | public function boot() |
11 | 11 | { |
12 | - $configPath = __DIR__ . '/../../config/laravel-model-caching.php'; |
|
12 | + $configPath = __DIR__.'/../../config/laravel-model-caching.php'; |
|
13 | 13 | $this->mergeConfigFrom($configPath, 'laravel-model-caching'); |
14 | 14 | $this->commands(Clear::class); |
15 | 15 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | public function avg($column) |
17 | 17 | { |
18 | - if (! $this->isCachable()) { |
|
18 | + if (!$this->isCachable()) { |
|
19 | 19 | return parent::avg($column); |
20 | 20 | } |
21 | 21 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | public function count($columns = "*") |
28 | 28 | { |
29 | - if (! $this->isCachable()) { |
|
29 | + if (!$this->isCachable()) { |
|
30 | 30 | return parent::count($columns); |
31 | 31 | } |
32 | 32 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function find($id, $columns = ["*"]) |
50 | 50 | { |
51 | - if (! $this->isCachable()) { |
|
51 | + if (!$this->isCachable()) { |
|
52 | 52 | return parent::find($id, $columns); |
53 | 53 | } |
54 | 54 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | public function first($columns = ["*"]) |
62 | 62 | { |
63 | - if (! $this->isCachable()) { |
|
63 | + if (!$this->isCachable()) { |
|
64 | 64 | return parent::first($columns); |
65 | 65 | } |
66 | 66 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | public function get($columns = ["*"]) |
73 | 73 | { |
74 | - if (! $this->isCachable()) { |
|
74 | + if (!$this->isCachable()) { |
|
75 | 75 | return parent::get($columns); |
76 | 76 | } |
77 | 77 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | public function max($column) |
98 | 98 | { |
99 | - if (! $this->isCachable()) { |
|
99 | + if (!$this->isCachable()) { |
|
100 | 100 | return parent::max($column); |
101 | 101 | } |
102 | 102 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | public function min($column) |
109 | 109 | { |
110 | - if (! $this->isCachable()) { |
|
110 | + if (!$this->isCachable()) { |
|
111 | 111 | return parent::min($column); |
112 | 112 | } |
113 | 113 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $pageName = "page", |
123 | 123 | $page = null |
124 | 124 | ) { |
125 | - if (! $this->isCachable()) { |
|
125 | + if (!$this->isCachable()) { |
|
126 | 126 | return parent::paginate($perPage, $columns, $pageName, $page); |
127 | 127 | } |
128 | 128 | |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | |
144 | 144 | foreach ($items as $key => $value) { |
145 | 145 | if (is_array($value)) { |
146 | - $result .= $key . $glue . $this->recursiveImplodeWithKey($value, $glue); |
|
146 | + $result .= $key.$glue.$this->recursiveImplodeWithKey($value, $glue); |
|
147 | 147 | |
148 | 148 | continue; |
149 | 149 | } |
150 | 150 | |
151 | - $result .= $glue . $key . $glue . $value; |
|
151 | + $result .= $glue.$key.$glue.$value; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $result; |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | |
157 | 157 | public function pluck($column, $key = null) |
158 | 158 | { |
159 | - if (! $this->isCachable()) { |
|
159 | + if (!$this->isCachable()) { |
|
160 | 160 | return parent::pluck($column, $key); |
161 | 161 | } |
162 | 162 | |
163 | - $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); |
|
163 | + $keyDifferentiator = "-pluck_{$column}".($key ? "_{$key}" : ""); |
|
164 | 164 | $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); |
165 | 165 | |
166 | 166 | return $this->cachedValue(func_get_args(), $cacheKey); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | |
169 | 169 | public function sum($column) |
170 | 170 | { |
171 | - if (! $this->isCachable()) { |
|
171 | + if (!$this->isCachable()) { |
|
172 | 172 | return parent::sum($column); |
173 | 173 | } |
174 | 174 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | public function value($column) |
188 | 188 | { |
189 | - if (! $this->isCachable()) { |
|
189 | + if (!$this->isCachable()) { |
|
190 | 190 | return parent::value($column); |
191 | 191 | } |
192 | 192 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | return $this->cache($cacheTags) |
256 | 256 | ->rememberForever( |
257 | 257 | $hashedCacheKey, |
258 | - function () use ($arguments, $cacheKey, $method) { |
|
258 | + function() use ($arguments, $cacheKey, $method) { |
|
259 | 259 | return [ |
260 | 260 | "key" => $cacheKey, |
261 | 261 | "value" => parent::{$method}(...$arguments), |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | $tags = collect($this->eagerLoad) |
30 | 30 | ->keys() |
31 | - ->map(function ($relationName) { |
|
31 | + ->map(function($relationName) { |
|
32 | 32 | $relation = $this->getRelation($relationName); |
33 | 33 | |
34 | 34 | return $this->getCachePrefix() |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | protected function getRelation(string $relationName) : Relation |
54 | 54 | { |
55 | 55 | return collect(explode('.', $relationName)) |
56 | - ->reduce(function ($carry, $name) { |
|
56 | + ->reduce(function($carry, $name) { |
|
57 | 57 | $carry = $carry ?: $this->model; |
58 | 58 | $carry = $this->getRelatedModel($carry); |
59 | 59 |
@@ -5,10 +5,10 @@ |
||
5 | 5 | protected function getCachePrefix() : string |
6 | 6 | { |
7 | 7 | return "genealabs:laravel-model-caching:" |
8 | - . $this->getConnectionName() . ":" |
|
9 | - . $this->getDatabaseName() . ":" |
|
8 | + . $this->getConnectionName().":" |
|
9 | + . $this->getDatabaseName().":" |
|
10 | 10 | . (config("laravel-model-caching.cache-prefix") |
11 | - ? config("laravel-model-caching.cache-prefix", "") . ":" |
|
11 | + ? config("laravel-model-caching.cache-prefix", "").":" |
|
12 | 12 | : ""); |
13 | 13 | } |
14 | 14 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
50 | 50 | |
51 | 51 | $this->cache() |
52 | - ->rememberForever($cacheKey, function () { |
|
52 | + ->rememberForever($cacheKey, function() { |
|
53 | 53 | return (new Carbon)->now(); |
54 | 54 | }); |
55 | 55 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | return "genealabs:laravel-model-caching:" |
61 | 61 | . (config('laravel-model-caching.cache-prefix') |
62 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
62 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
63 | 63 | : ""); |
64 | 64 | } |
65 | 65 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | public function getModelCacheCooldown(Model $instance) : array |
95 | 95 | { |
96 | - if (! $instance->cacheCooldownSeconds) { |
|
96 | + if (!$instance->cacheCooldownSeconds) { |
|
97 | 97 | return [null, null, null]; |
98 | 98 | } |
99 | 99 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | [$cacheCooldown, $invalidatedAt, $savedAt] = $this |
103 | 103 | ->getCacheCooldownDetails($instance, $cachePrefix, $modelClassName); |
104 | 104 | |
105 | - if (! $cacheCooldown || $cacheCooldown === 0) { |
|
105 | + if (!$cacheCooldown || $cacheCooldown === 0) { |
|
106 | 106 | return [null, null, null]; |
107 | 107 | } |
108 | 108 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | { |
132 | 132 | [$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance); |
133 | 133 | |
134 | - if (! $cacheCooldown |
|
134 | + if (!$cacheCooldown |
|
135 | 135 | || (new Carbon)->now()->diffInSeconds($invalidatedAt) < $cacheCooldown |
136 | 136 | ) { |
137 | 137 | return; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | [$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance); |
158 | 158 | |
159 | - if (! $cacheCooldown) { |
|
159 | + if (!$cacheCooldown) { |
|
160 | 160 | $instance->flushCache(); |
161 | 161 | |
162 | 162 | return; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public function isCachable() : bool |
173 | 173 | { |
174 | 174 | return $this->isCachable |
175 | - && ! config('laravel-model-caching.disabled'); |
|
175 | + && !config('laravel-model-caching.disabled'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | protected function setCacheCooldownSavedAtTimestamp(Model $instance) |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
183 | 183 | |
184 | 184 | $instance->cache() |
185 | - ->rememberForever($cacheKey, function () { |
|
185 | + ->rememberForever($cacheKey, function() { |
|
186 | 186 | return (new Carbon)->now(); |
187 | 187 | }); |
188 | 188 | } |
@@ -20,22 +20,22 @@ discard block |
||
20 | 20 | $key = $instance->makeCacheKey(); |
21 | 21 | |
22 | 22 | return $instance->cache($tags) |
23 | - ->rememberForever($key, function () use ($columns) { |
|
23 | + ->rememberForever($key, function() use ($columns) { |
|
24 | 24 | return parent::all($columns); |
25 | 25 | }); |
26 | 26 | } |
27 | 27 | |
28 | 28 | public static function bootCachable() |
29 | 29 | { |
30 | - static::created(function ($instance) { |
|
30 | + static::created(function($instance) { |
|
31 | 31 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
32 | 32 | }); |
33 | 33 | |
34 | - static::deleted(function ($instance) { |
|
34 | + static::deleted(function($instance) { |
|
35 | 35 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
36 | 36 | }); |
37 | 37 | |
38 | - static::saved(function ($instance) { |
|
38 | + static::saved(function($instance) { |
|
39 | 39 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
40 | 40 | }); |
41 | 41 | |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | // $instance->checkCooldownAndFlushAfterPersisting($instance); |
45 | 45 | // }); |
46 | 46 | |
47 | - static::pivotAttached(function ($instance) { |
|
47 | + static::pivotAttached(function($instance) { |
|
48 | 48 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
49 | 49 | }); |
50 | 50 | |
51 | - static::pivotDetached(function ($instance) { |
|
51 | + static::pivotDetached(function($instance) { |
|
52 | 52 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
53 | 53 | }); |
54 | 54 | |
55 | - static::pivotUpdated(function ($instance) { |
|
55 | + static::pivotUpdated(function($instance) { |
|
56 | 56 | $instance->checkCooldownAndFlushAfterPersisting($instance); |
57 | 57 | }); |
58 | 58 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function newEloquentBuilder($query) |
70 | 70 | { |
71 | - if (! $this->isCachable()) { |
|
71 | + if (!$this->isCachable()) { |
|
72 | 72 | $this->isCachable = true; |
73 | 73 | |
74 | 74 | return new EloquentBuilder($query); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | EloquentBuilder $query, |
91 | 91 | int $seconds = null |
92 | 92 | ) : EloquentBuilder { |
93 | - if (! $seconds) { |
|
93 | + if (!$seconds) { |
|
94 | 94 | $seconds = $this->cacheCooldownSeconds; |
95 | 95 | } |
96 | 96 | |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds"; |
100 | 100 | |
101 | 101 | $this->cache() |
102 | - ->rememberForever($cacheKey, function () use ($seconds) { |
|
102 | + ->rememberForever($cacheKey, function() use ($seconds) { |
|
103 | 103 | return $seconds; |
104 | 104 | }); |
105 | 105 | |
106 | 106 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at"; |
107 | 107 | $this->cache() |
108 | - ->rememberForever($cacheKey, function () { |
|
108 | + ->rememberForever($cacheKey, function() { |
|
109 | 109 | return (new Carbon)->now(); |
110 | 110 | }); |
111 | 111 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | protected function getLimitClause() : string |
57 | 57 | { |
58 | - if (! $this->query->limit) { |
|
58 | + if (!$this->query->limit) { |
|
59 | 59 | return ""; |
60 | 60 | } |
61 | 61 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | protected function getOffsetClause() : string |
77 | 77 | { |
78 | - if (! $this->query->offset) { |
|
78 | + if (!$this->query->offset) { |
|
79 | 79 | return ""; |
80 | 80 | } |
81 | 81 | |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | $orders = collect($this->query->orders); |
88 | 88 | |
89 | 89 | return $orders |
90 | - ->reduce(function ($carry, $order) { |
|
90 | + ->reduce(function($carry, $order) { |
|
91 | 91 | if (($order["type"] ?? "") === "Raw") { |
92 | - return $carry . "_orderByRaw_" . (new Str)->slug($order["sql"]); |
|
92 | + return $carry."_orderByRaw_".(new Str)->slug($order["sql"]); |
|
93 | 93 | } |
94 | 94 | |
95 | - return $carry . "_orderBy_" . $order["column"] . "_" . $order["direction"]; |
|
95 | + return $carry."_orderBy_".$order["column"]."_".$order["direction"]; |
|
96 | 96 | }) |
97 | 97 | ?: ""; |
98 | 98 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | return ""; |
104 | 104 | } |
105 | 105 | |
106 | - return "_" . implode("_", $columns); |
|
106 | + return "_".implode("_", $columns); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | protected function getTypeClause($where) : string |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | $values = $this->getValuesFromWhere($where); |
125 | 125 | $values = $this->getValuesFromBindings($where, $values); |
126 | 126 | |
127 | - return "_" . $values; |
|
127 | + return "_".$values; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | protected function getValuesFromWhere(array $where) : string |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $subKey = str_replace($prefix, "", $subKey); |
137 | 137 | $subKey = str_replace($this->getModelSlug(), "", $subKey); |
138 | 138 | $classParts = explode("\\", get_class($this->model)); |
139 | - $subKey = strtolower(array_pop($classParts)) . $subKey; |
|
139 | + $subKey = strtolower(array_pop($classParts)).$subKey; |
|
140 | 140 | |
141 | 141 | return $subKey; |
142 | 142 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $this->currentBinding++; |
156 | 156 | |
157 | 157 | if ($where["type"] === "between") { |
158 | - $values .= "_" . $this->query->bindings["where"][$this->currentBinding]; |
|
158 | + $values .= "_".$this->query->bindings["where"][$this->currentBinding]; |
|
159 | 159 | $this->currentBinding++; |
160 | 160 | } |
161 | 161 | } |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | |
166 | 166 | protected function getWhereClauses(array $wheres = []) : string |
167 | 167 | { |
168 | - return "" . $this->getWheres($wheres) |
|
169 | - ->reduce(function ($carry, $where) { |
|
168 | + return "".$this->getWheres($wheres) |
|
169 | + ->reduce(function($carry, $where) { |
|
170 | 170 | $value = $carry; |
171 | 171 | $value .= $this->getNestedClauses($where); |
172 | 172 | $value .= $this->getColumnClauses($where); |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | |
181 | 181 | protected function getNestedClauses(array $where) : string |
182 | 182 | { |
183 | - if (! in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
183 | + if (!in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
184 | 184 | return ""; |
185 | 185 | } |
186 | 186 | |
187 | - return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres); |
|
187 | + return "-".strtolower($where["type"]).$this->getWhereClauses($where["query"]->wheres); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | protected function getColumnClauses(array $where) : string |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | protected function getInClauses(array $where) : string |
200 | 200 | { |
201 | - if (! in_array($where["type"], ["In"])) { |
|
201 | + if (!in_array($where["type"], ["In"])) { |
|
202 | 202 | return ""; |
203 | 203 | } |
204 | 204 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | |
211 | 211 | protected function getInAndNotInClauses(array $where) : string |
212 | 212 | { |
213 | - if (! in_array($where["type"], ["In", "NotIn"])) { |
|
213 | + if (!in_array($where["type"], ["In", "NotIn"])) { |
|
214 | 214 | return ""; |
215 | 215 | } |
216 | 216 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | continue; |
249 | 249 | } |
250 | 250 | |
251 | - $result .= $glue . $value; |
|
251 | + $result .= $glue.$value; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $result; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $clause = "_{$where["boolean"]}"; |
265 | 265 | |
266 | 266 | while (count($queryParts) > 1) { |
267 | - $clause .= "_" . array_shift($queryParts); |
|
267 | + $clause .= "_".array_shift($queryParts); |
|
268 | 268 | $clause .= $this->query->bindings["where"][$this->currentBinding]; |
269 | 269 | $this->currentBinding++; |
270 | 270 | } |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | $lastPart = array_shift($queryParts); |
273 | 273 | |
274 | 274 | if ($lastPart) { |
275 | - $clause .= "_" . $lastPart; |
|
275 | + $clause .= "_".$lastPart; |
|
276 | 276 | } |
277 | 277 | |
278 | - return "-" . str_replace(" ", "_", $clause); |
|
278 | + return "-".str_replace(" ", "_", $clause); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | protected function getOtherClauses(array $where) : string |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | return ""; |
310 | 310 | } |
311 | 311 | |
312 | - return $eagerLoads->keys()->reduce(function ($carry, $related) { |
|
313 | - if (! method_exists($this->model, $related)) { |
|
312 | + return $eagerLoads->keys()->reduce(function($carry, $related) { |
|
313 | + if (!method_exists($this->model, $related)) { |
|
314 | 314 | return "{$carry}-{$related}"; |
315 | 315 | } |
316 | 316 |