@@ -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 | |
@@ -63,6 +63,6 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | protected function getTagName() : string |
| 65 | 65 | { |
| 66 | - return $this->getCachePrefix() . str_slug(get_class($this->model)); |
|
| 66 | + return $this->getCachePrefix().str_slug(get_class($this->model)); |
|
| 67 | 67 | } |
| 68 | 68 | } |
@@ -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 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function avg($column) |
| 16 | 16 | { |
| 17 | - if (! $this->isCachable()) { |
|
| 17 | + if (!$this->isCachable()) { |
|
| 18 | 18 | return parent::avg($column); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function count($columns = "*") |
| 27 | 27 | { |
| 28 | - if (! $this->isCachable()) { |
|
| 28 | + if (!$this->isCachable()) { |
|
| 29 | 29 | return parent::count($columns); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function find($id, $columns = ["*"]) |
| 49 | 49 | { |
| 50 | - if (! $this->isCachable()) { |
|
| 50 | + if (!$this->isCachable()) { |
|
| 51 | 51 | return parent::find($id, $columns); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function first($columns = ["*"]) |
| 60 | 60 | { |
| 61 | - if (! $this->isCachable()) { |
|
| 61 | + if (!$this->isCachable()) { |
|
| 62 | 62 | return parent::first($columns); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | public function get($columns = ["*"]) |
| 71 | 71 | { |
| 72 | - if (! $this->isCachable()) { |
|
| 72 | + if (!$this->isCachable()) { |
|
| 73 | 73 | return parent::get($columns); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | public function max($column) |
| 89 | 89 | { |
| 90 | - if (! $this->isCachable()) { |
|
| 90 | + if (!$this->isCachable()) { |
|
| 91 | 91 | return parent::max($column); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function min($column) |
| 100 | 100 | { |
| 101 | - if (! $this->isCachable()) { |
|
| 101 | + if (!$this->isCachable()) { |
|
| 102 | 102 | return parent::min($column); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $pageName = "page", |
| 114 | 114 | $page = null |
| 115 | 115 | ) { |
| 116 | - if (! $this->isCachable()) { |
|
| 116 | + if (!$this->isCachable()) { |
|
| 117 | 117 | return parent::paginate($perPage, $columns, $pageName, $page); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,11 +125,11 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function pluck($column, $key = null) |
| 127 | 127 | { |
| 128 | - if (! $this->isCachable()) { |
|
| 128 | + if (!$this->isCachable()) { |
|
| 129 | 129 | return parent::pluck($column, $key); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); |
|
| 132 | + $keyDifferentiator = "-pluck_{$column}".($key ? "_{$key}" : ""); |
|
| 133 | 133 | $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); |
| 134 | 134 | |
| 135 | 135 | return $this->cachedValue(func_get_args(), $cacheKey); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | public function sum($column) |
| 139 | 139 | { |
| 140 | - if (! $this->isCachable()) { |
|
| 140 | + if (!$this->isCachable()) { |
|
| 141 | 141 | return parent::sum($column); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | public function value($column) |
| 157 | 157 | { |
| 158 | - if (! $this->isCachable()) { |
|
| 158 | + if (!$this->isCachable()) { |
|
| 159 | 159 | return parent::value($column); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | return $this->cache($cacheTags) |
| 225 | 225 | ->rememberForever( |
| 226 | 226 | $hashedCacheKey, |
| 227 | - function () use ($arguments, $cacheKey, $method) { |
|
| 227 | + function() use ($arguments, $cacheKey, $method) { |
|
| 228 | 228 | return [ |
| 229 | 229 | "key" => $cacheKey, |
| 230 | 230 | "value" => parent::{$method}(...$arguments), |
@@ -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 | } |
@@ -5,10 +5,10 @@ |
||
| 5 | 5 | protected function getCachePrefix() : string |
| 6 | 6 | { |
| 7 | 7 | return "genealabs:laravel-model-caching:" |
| 8 | - . $this->getDatabaseConnectionName() . ":" |
|
| 9 | - . $this->getDatabaseName() . ":" |
|
| 8 | + . $this->getDatabaseConnectionName().":" |
|
| 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 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | protected function getLimitClause() : string |
| 52 | 52 | { |
| 53 | - if (! $this->query->limit) { |
|
| 53 | + if (!$this->query->limit) { |
|
| 54 | 54 | return ""; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | protected function getOffsetClause() : string |
| 66 | 66 | { |
| 67 | - if (! $this->query->offset) { |
|
| 67 | + if (!$this->query->offset) { |
|
| 68 | 68 | return ""; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | $orders = collect($this->query->orders); |
| 77 | 77 | |
| 78 | 78 | return $orders |
| 79 | - ->reduce(function ($carry, $order) { |
|
| 79 | + ->reduce(function($carry, $order) { |
|
| 80 | 80 | if (($order["type"] ?? "") === "Raw") { |
| 81 | - return $carry . "_orderByRaw_" . str_slug($order["sql"]); |
|
| 81 | + return $carry."_orderByRaw_".str_slug($order["sql"]); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return $carry . "_orderBy_" . $order["column"] . "_" . $order["direction"]; |
|
| 84 | + return $carry."_orderBy_".$order["column"]."_".$order["direction"]; |
|
| 85 | 85 | }) |
| 86 | 86 | ?: ""; |
| 87 | 87 | } |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | return ""; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - return "_" . implode("_", $columns); |
|
| 95 | + return "_".implode("_", $columns); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | protected function getTypeClause($where) : string |
| 99 | 99 | { |
| 100 | - $type =in_array($where["type"], ["In", "NotIn", "Null", "NotNull", "between"]) |
|
| 100 | + $type = in_array($where["type"], ["In", "NotIn", "Null", "NotNull", "between"]) |
|
| 101 | 101 | ? strtolower($where["type"]) |
| 102 | 102 | : strtolower($where["operator"]); |
| 103 | 103 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | |
| 118 | - return "_" . $values; |
|
| 118 | + return "_".$values; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | protected function getValuesFromWhere(array $where) : string |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | protected function getValuesFromBindings(array $where, string $values) : string |
| 131 | 131 | { |
| 132 | - if (! $values && ($this->query->bindings["where"] ?? false)) { |
|
| 132 | + if (!$values && ($this->query->bindings["where"] ?? false)) { |
|
| 133 | 133 | $values = $this->query->bindings["where"][$this->currentBinding]; |
| 134 | 134 | $this->currentBinding++; |
| 135 | 135 | |
| 136 | 136 | if ($where["type"] === "between") { |
| 137 | - $values .= "_" . $this->query->bindings["where"][$this->currentBinding]; |
|
| 137 | + $values .= "_".$this->query->bindings["where"][$this->currentBinding]; |
|
| 138 | 138 | $this->currentBinding++; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | protected function getWhereClauses(array $wheres = []) : string |
| 146 | 146 | { |
| 147 | - return "" . $this->getWheres($wheres) |
|
| 148 | - ->reduce(function ($carry, $where) { |
|
| 147 | + return "".$this->getWheres($wheres) |
|
| 148 | + ->reduce(function($carry, $where) { |
|
| 149 | 149 | $value = $carry; |
| 150 | 150 | $value .= $this->getNestedClauses($where); |
| 151 | 151 | $value .= $this->getColumnClauses($where); |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | protected function getNestedClauses(array $where) : string |
| 162 | 162 | { |
| 163 | - if (! in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
| 163 | + if (!in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
| 164 | 164 | return ""; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $this->currentBinding++; |
| 168 | 168 | |
| 169 | - return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres); |
|
| 169 | + return "-".strtolower($where["type"]).$this->getWhereClauses($where["query"]->wheres); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | protected function getColumnClauses(array $where) : string |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | protected function getInClauses(array $where) : string |
| 184 | 184 | { |
| 185 | - if (! in_array($where["type"], ["In"])) { |
|
| 185 | + if (!in_array($where["type"], ["In"])) { |
|
| 186 | 186 | return ""; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | protected function getNotInClauses(array $where) : string |
| 196 | 196 | { |
| 197 | - if (! in_array($where["type"], ["NotIn"])) { |
|
| 197 | + if (!in_array($where["type"], ["NotIn"])) { |
|
| 198 | 198 | return ""; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | continue; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $result .= $glue . $value; |
|
| 218 | + $result .= $glue.$value; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | return $result; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $clause = "_{$where["boolean"]}"; |
| 232 | 232 | |
| 233 | 233 | while (count($queryParts) > 1) { |
| 234 | - $clause .= "_" . array_shift($queryParts); |
|
| 234 | + $clause .= "_".array_shift($queryParts); |
|
| 235 | 235 | $clause .= $this->query->bindings["where"][$this->currentBinding]; |
| 236 | 236 | $this->currentBinding++; |
| 237 | 237 | } |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | $lastPart = array_shift($queryParts); |
| 240 | 240 | |
| 241 | 241 | if ($lastPart) { |
| 242 | - $clause .= "_" . $lastPart; |
|
| 242 | + $clause .= "_".$lastPart; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - return "-" . str_replace(" ", "_", $clause); |
|
| 245 | + return "-".str_replace(" ", "_", $clause); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | protected function getOtherClauses(array $where) : string |
@@ -276,6 +276,6 @@ discard block |
||
| 276 | 276 | return ""; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - return "-" . implode("-", $eagerLoads->keys()->toArray()); |
|
| 279 | + return "-".implode("-", $eagerLoads->keys()->toArray()); |
|
| 280 | 280 | } |
| 281 | 281 | } |
@@ -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 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | [$cacheCooldown, $invalidatedAt, $savedAt] = $this |
| 96 | 96 | ->getCacheCooldownDetails($instance, $cachePrefix, $modelClassName); |
| 97 | 97 | |
| 98 | - if (! $cacheCooldown || $cacheCooldown === 0) { |
|
| 98 | + if (!$cacheCooldown || $cacheCooldown === 0) { |
|
| 99 | 99 | return [null, null, null]; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | [$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance); |
| 130 | 130 | |
| 131 | - if (! $cacheCooldown |
|
| 131 | + if (!$cacheCooldown |
|
| 132 | 132 | || (new Carbon)->now()->diffInSeconds($invalidatedAt) < $cacheCooldown |
| 133 | 133 | ) { |
| 134 | 134 | return; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | { |
| 154 | 154 | [$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance); |
| 155 | 155 | |
| 156 | - if (! $cacheCooldown) { |
|
| 156 | + if (!$cacheCooldown) { |
|
| 157 | 157 | $instance->flushCache(); |
| 158 | 158 | |
| 159 | 159 | return; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | public function isCachable() : bool |
| 170 | 170 | { |
| 171 | 171 | return $this->isCachable |
| 172 | - && ! config('laravel-model-caching.disabled'); |
|
| 172 | + && !config('laravel-model-caching.disabled'); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | protected function setCacheCooldownSavedAtTimestamp(Model $instance) |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
| 180 | 180 | |
| 181 | 181 | $instance->cache() |
| 182 | - ->rememberForever($cacheKey, function () { |
|
| 182 | + ->rememberForever($cacheKey, function() { |
|
| 183 | 183 | return (new Carbon)->now(); |
| 184 | 184 | }); |
| 185 | 185 | } |
@@ -18,30 +18,30 @@ discard block |
||
| 18 | 18 | $key = $instance->makeCacheKey(); |
| 19 | 19 | |
| 20 | 20 | return $instance->cache($tags) |
| 21 | - ->rememberForever($key, function () use ($columns) { |
|
| 21 | + ->rememberForever($key, function() use ($columns) { |
|
| 22 | 22 | return parent::all($columns); |
| 23 | 23 | }); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public static function bootCachable() |
| 27 | 27 | { |
| 28 | - static::deleted(function ($instance) { |
|
| 28 | + static::deleted(function($instance) { |
|
| 29 | 29 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
| 30 | 30 | }); |
| 31 | 31 | |
| 32 | - static::saved(function ($instance) { |
|
| 32 | + static::saved(function($instance) { |
|
| 33 | 33 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
| 34 | 34 | }); |
| 35 | 35 | |
| 36 | - static::pivotAttached(function ($instance) { |
|
| 36 | + static::pivotAttached(function($instance) { |
|
| 37 | 37 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
| 38 | 38 | }); |
| 39 | 39 | |
| 40 | - static::pivotDetached(function ($instance) { |
|
| 40 | + static::pivotDetached(function($instance) { |
|
| 41 | 41 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | - static::pivotUpdated(function ($instance) { |
|
| 44 | + static::pivotUpdated(function($instance) { |
|
| 45 | 45 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
| 46 | 46 | }); |
| 47 | 47 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function newEloquentBuilder($query) |
| 59 | 59 | { |
| 60 | - if (! $this->isCachable()) { |
|
| 60 | + if (!$this->isCachable()) { |
|
| 61 | 61 | $this->isCachable = true; |
| 62 | 62 | |
| 63 | 63 | return new EloquentBuilder($query); |
@@ -84,13 +84,13 @@ discard block |
||
| 84 | 84 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds"; |
| 85 | 85 | |
| 86 | 86 | $this->cache() |
| 87 | - ->rememberForever($cacheKey, function () use ($seconds) { |
|
| 87 | + ->rememberForever($cacheKey, function() use ($seconds) { |
|
| 88 | 88 | return $seconds; |
| 89 | 89 | }); |
| 90 | 90 | |
| 91 | 91 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at"; |
| 92 | 92 | $this->cache() |
| 93 | - ->rememberForever($cacheKey, function () { |
|
| 93 | + ->rememberForever($cacheKey, function() { |
|
| 94 | 94 | return (new Carbon)->now(); |
| 95 | 95 | }); |
| 96 | 96 | |