@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | { |
| 15 | 15 | return "genealabs:laravel-model-caching:" |
| 16 | 16 | . (config("laravel-model-caching.cache-prefix") |
| 17 | - ? config("laravel-model-caching.cache-prefix", "") . ":" |
|
| 17 | + ? config("laravel-model-caching.cache-prefix", "").":" |
|
| 18 | 18 | : ""); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | protected function getLimitClause() : string |
| 56 | 56 | { |
| 57 | - if (! $this->query->limit) { |
|
| 57 | + if (!$this->query->limit) { |
|
| 58 | 58 | return ""; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | protected function getOffsetClause() : string |
| 70 | 70 | { |
| 71 | - if (! $this->query->offset) { |
|
| 71 | + if (!$this->query->offset) { |
|
| 72 | 72 | return ""; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | $orders = collect($this->query->orders); |
| 81 | 81 | |
| 82 | 82 | return $orders |
| 83 | - ->reduce(function ($carry, $order) { |
|
| 83 | + ->reduce(function($carry, $order) { |
|
| 84 | 84 | if (($order["type"] ?? "") === "Raw") { |
| 85 | - return $carry . "_orderByRaw_" . str_slug($order["sql"]); |
|
| 85 | + return $carry."_orderByRaw_".str_slug($order["sql"]); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return $carry . "_orderBy_" . $order["column"] . "_" . $order["direction"]; |
|
| 88 | + return $carry."_orderBy_".$order["column"]."_".$order["direction"]; |
|
| 89 | 89 | }) |
| 90 | 90 | ?: ""; |
| 91 | 91 | } |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | return ""; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - return "_" . implode("_", $columns); |
|
| 99 | + return "_".implode("_", $columns); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | protected function getTypeClause($where) : string |
| 103 | 103 | { |
| 104 | - $type =in_array($where["type"], ["In", "NotIn", "Null", "NotNull", "between"]) |
|
| 104 | + $type = in_array($where["type"], ["In", "NotIn", "Null", "NotNull", "between"]) |
|
| 105 | 105 | ? strtolower($where["type"]) |
| 106 | 106 | : strtolower($where["operator"]); |
| 107 | 107 | |
@@ -118,17 +118,17 @@ discard block |
||
| 118 | 118 | ? implode("_", $where["values"]) |
| 119 | 119 | : ""; |
| 120 | 120 | |
| 121 | - if (! $values && $this->query->bindings["where"] ?? false) { |
|
| 121 | + if (!$values && $this->query->bindings["where"] ?? false) { |
|
| 122 | 122 | $values = implode("_", $this->query->bindings["where"]); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return "_" . $values; |
|
| 125 | + return "_".$values; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | protected function getWhereClauses(array $wheres = []) : string |
| 129 | 129 | { |
| 130 | 130 | return $this->getWheres($wheres) |
| 131 | - ->reduce(function ($carry, $where) { |
|
| 131 | + ->reduce(function($carry, $where) { |
|
| 132 | 132 | $value = $this->getNestedClauses($where); |
| 133 | 133 | $value .= $this->getColumnClauses($where); |
| 134 | 134 | $value .= $this->getRawClauses($where); |
@@ -141,11 +141,11 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | protected function getNestedClauses(array $where) : string |
| 143 | 143 | { |
| 144 | - if (! in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
| 144 | + if (!in_array($where["type"], ["Exists", "Nested", "NotExists"])) { |
|
| 145 | 145 | return ""; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - return "_" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres); |
|
| 148 | + return "_".strtolower($where["type"]).$this->getWhereClauses($where["query"]->wheres); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | protected function getColumnClauses(array $where) : string |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | return ""; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - return "_{$where["boolean"]}_" . str_slug($where["sql"]); |
|
| 166 | + return "_{$where["boolean"]}_".str_slug($where["sql"]); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | protected function getOtherClauses(array $where, string $carry = null) : string |
@@ -197,6 +197,6 @@ discard block |
||
| 197 | 197 | return ""; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - return "-" . implode("-", $eagerLoads->keys()->toArray()); |
|
| 200 | + return "-".implode("-", $eagerLoads->keys()->toArray()); |
|
| 201 | 201 | } |
| 202 | 202 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function avg($column) |
| 14 | 14 | { |
| 15 | - if (! $this->isCachable()) { |
|
| 15 | + if (!$this->isCachable()) { |
|
| 16 | 16 | return parent::avg($column); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -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 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function cursor() |
| 40 | 40 | { |
| 41 | - if (! $this->isCachable()) { |
|
| 41 | + if (!$this->isCachable()) { |
|
| 42 | 42 | return collect(parent::cursor()); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function find($id, $columns = ["*"]) |
| 64 | 64 | { |
| 65 | - if (! $this->isCachable()) { |
|
| 65 | + if (!$this->isCachable()) { |
|
| 66 | 66 | return parent::find($id, $columns); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function first($columns = ["*"]) |
| 77 | 77 | { |
| 78 | - if (! $this->isCachable()) { |
|
| 78 | + if (!$this->isCachable()) { |
|
| 79 | 79 | return parent::first($columns); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | public function get($columns = ["*"]) |
| 90 | 90 | { |
| 91 | - if (! $this->isCachable()) { |
|
| 91 | + if (!$this->isCachable()) { |
|
| 92 | 92 | return parent::get($columns); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | public function max($column) |
| 103 | 103 | { |
| 104 | - if (! $this->isCachable()) { |
|
| 104 | + if (!$this->isCachable()) { |
|
| 105 | 105 | return parent::max($column); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | public function min($column) |
| 116 | 116 | { |
| 117 | - if (! $this->isCachable()) { |
|
| 117 | + if (!$this->isCachable()) { |
|
| 118 | 118 | return parent::min($column); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $pageName = "page", |
| 132 | 132 | $page = null |
| 133 | 133 | ) { |
| 134 | - if (! $this->isCachable()) { |
|
| 134 | + if (!$this->isCachable()) { |
|
| 135 | 135 | return parent::paginate($perPage, $columns, $pageName, $page); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | public function pluck($column, $key = null) |
| 147 | 147 | { |
| 148 | - if (! $this->isCachable()) { |
|
| 148 | + if (!$this->isCachable()) { |
|
| 149 | 149 | return parent::pluck($column, $key); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $keyDifferentiator = "-pluck_{$column}" . ($key ? "_{$key}" : ""); |
|
| 152 | + $keyDifferentiator = "-pluck_{$column}".($key ? "_{$key}" : ""); |
|
| 153 | 153 | $arguments = func_get_args(); |
| 154 | 154 | $cacheKey = $this->makeCacheKey([$column], null, $keyDifferentiator); |
| 155 | 155 | $method = "pluck"; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | public function sum($column) |
| 161 | 161 | { |
| 162 | - if (! $this->isCachable()) { |
|
| 162 | + if (!$this->isCachable()) { |
|
| 163 | 163 | return parent::sum($column); |
| 164 | 164 | } |
| 165 | 165 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | public function value($column) |
| 174 | 174 | { |
| 175 | - if (! $this->isCachable()) { |
|
| 175 | + if (!$this->isCachable()) { |
|
| 176 | 176 | return parent::value($column); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | return $this->cache($cacheTags) |
| 243 | 243 | ->rememberForever( |
| 244 | 244 | $hashedCacheKey, |
| 245 | - function () use ($arguments, $cacheKey, $method) { |
|
| 245 | + function() use ($arguments, $cacheKey, $method) { |
|
| 246 | 246 | return [ |
| 247 | 247 | "key" => $cacheKey, |
| 248 | 248 | "value" => parent::{$method}(...$arguments), |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $usesCachableTrait = collect(class_uses($this)) |
| 35 | 35 | ->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable"); |
| 36 | 36 | |
| 37 | - if (! $usesCachableTrait) { |
|
| 37 | + if (!$usesCachableTrait) { |
|
| 38 | 38 | array_push($tags, str_slug(get_called_class())); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | if ($cacheCooldown) { |
| 62 | 62 | $cachePrefix = "genealabs:laravel-model-caching:" |
| 63 | 63 | . (config('laravel-model-caching.cache-prefix') |
| 64 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
| 64 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
| 65 | 65 | : ""); |
| 66 | 66 | $modelClassName = get_class($this); |
| 67 | 67 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
| 68 | 68 | |
| 69 | 69 | $this->cache() |
| 70 | - ->rememberForever($cacheKey, function () { |
|
| 70 | + ->rememberForever($cacheKey, function() { |
|
| 71 | 71 | return now(); |
| 72 | 72 | }); |
| 73 | 73 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | $cachePrefix = "genealabs:laravel-model-caching:" |
| 100 | 100 | . (config('laravel-model-caching.cache-prefix') |
| 101 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
| 101 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
| 102 | 102 | : ""); |
| 103 | 103 | $modelClassName = get_class($instance); |
| 104 | 104 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ->cache() |
| 107 | 107 | ->get("{$cachePrefix}:{$modelClassName}-cooldown:seconds"); |
| 108 | 108 | |
| 109 | - if (! $cacheCooldown) { |
|
| 109 | + if (!$cacheCooldown) { |
|
| 110 | 110 | return [null, null, null]; |
| 111 | 111 | } |
| 112 | 112 | |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | [$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance); |
| 131 | 131 | |
| 132 | - if (! $cacheCooldown) { |
|
| 132 | + if (!$cacheCooldown) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if (now()->diffInSeconds($invalidatedAt) >= $cacheCooldown) { |
| 137 | 137 | $cachePrefix = "genealabs:laravel-model-caching:" |
| 138 | 138 | . (config('laravel-model-caching.cache-prefix') |
| 139 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
| 139 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
| 140 | 140 | : ""); |
| 141 | 141 | $modelClassName = get_class($instance); |
| 142 | 142 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | [$cacheCooldown, $invalidatedAt, $savedAt] = $instance->getModelCacheCooldown($instance); |
| 159 | 159 | |
| 160 | - if (! $cacheCooldown) { |
|
| 160 | + if (!$cacheCooldown) { |
|
| 161 | 161 | $instance->flushCache(); |
| 162 | 162 | |
| 163 | 163 | return; |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | if ($cacheCooldown) { |
| 167 | 167 | $cachePrefix = "genealabs:laravel-model-caching:" |
| 168 | 168 | . (config('laravel-model-caching.cache-prefix') |
| 169 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
| 169 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
| 170 | 170 | : ""); |
| 171 | 171 | $modelClassName = get_class($instance); |
| 172 | 172 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at"; |
| 173 | 173 | |
| 174 | 174 | $instance->cache() |
| 175 | - ->rememberForever($cacheKey, function () { |
|
| 175 | + ->rememberForever($cacheKey, function() { |
|
| 176 | 176 | return now(); |
| 177 | 177 | }); |
| 178 | 178 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | public static function bootCachable() |
| 188 | 188 | { |
| 189 | 189 | // TODO: add for deleted,updated,etc? |
| 190 | - static::saved(function ($instance) { |
|
| 190 | + static::saved(function($instance) { |
|
| 191 | 191 | $instance->checkCooldownAndFlushAfterPersiting($instance); |
| 192 | 192 | }); |
| 193 | 193 | } |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | $key = $instance->makeCacheKey(); |
| 205 | 205 | |
| 206 | 206 | return $instance->cache($tags) |
| 207 | - ->rememberForever($key, function () use ($columns) { |
|
| 207 | + ->rememberForever($key, function() use ($columns) { |
|
| 208 | 208 | return parent::all($columns); |
| 209 | 209 | }); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | public function newEloquentBuilder($query) |
| 213 | 213 | { |
| 214 | - if (! $this->isCachable()) { |
|
| 214 | + if (!$this->isCachable()) { |
|
| 215 | 215 | $this->isCachable = true; |
| 216 | 216 | |
| 217 | 217 | return new EloquentBuilder($query); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | public function isCachable() : bool |
| 224 | 224 | { |
| 225 | 225 | return $this->isCachable |
| 226 | - && ! config('laravel-model-caching.disabled'); |
|
| 226 | + && !config('laravel-model-caching.disabled'); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | public function scopeWithCacheCooldownSeconds( |
@@ -232,19 +232,19 @@ discard block |
||
| 232 | 232 | ) : EloquentBuilder { |
| 233 | 233 | $cachePrefix = "genealabs:laravel-model-caching:" |
| 234 | 234 | . (config('laravel-model-caching.cache-prefix') |
| 235 | - ? config('laravel-model-caching.cache-prefix', '') . ":" |
|
| 235 | + ? config('laravel-model-caching.cache-prefix', '').":" |
|
| 236 | 236 | : ""); |
| 237 | 237 | $modelClassName = get_class($this); |
| 238 | 238 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds"; |
| 239 | 239 | |
| 240 | 240 | $this->cache() |
| 241 | - ->rememberForever($cacheKey, function () use ($seconds) { |
|
| 241 | + ->rememberForever($cacheKey, function() use ($seconds) { |
|
| 242 | 242 | return $seconds; |
| 243 | 243 | }); |
| 244 | 244 | |
| 245 | 245 | $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at"; |
| 246 | 246 | $this->cache() |
| 247 | - ->rememberForever($cacheKey, function () use ($seconds) { |
|
| 247 | + ->rememberForever($cacheKey, function() use ($seconds) { |
|
| 248 | 248 | return now(); |
| 249 | 249 | }); |
| 250 | 250 | |