Passed
Pull Request — master (#211)
by Motohiro
04:45
created
src/CacheTags.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Traits/BuilderCaching.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Console/Commands/Clear.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Providers/Service.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Traits/CachePrefixing.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Traits/Caching.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/CachedBuilder.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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),
Please login to merge, or discard this patch.
src/CacheKey.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,7 +92,7 @@  discard block
 block discarded – undo
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
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
 
117 117
 
118
-        return "_" . $values;
118
+        return "_".$values;
119 119
     }
120 120
 
121 121
     protected function getValuesFromWhere(array $where) : string
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             $subKey = str_replace($prefix, "", $subKey);
128 128
             $subKey = str_replace($this->getModelSlug(), "", $subKey);
129 129
             $classParts = explode("\\", get_class($this->model));
130
-            $subKey = strtolower(array_pop($classParts)) . $subKey;
130
+            $subKey = strtolower(array_pop($classParts)).$subKey;
131 131
 
132 132
             return $subKey;
133 133
         }
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
 
142 142
     protected function getValuesFromBindings(array $where, string $values) : string
143 143
     {
144
-        if (! $values && ($this->query->bindings["where"][$this->currentBinding] ?? false)) {
144
+        if (!$values && ($this->query->bindings["where"][$this->currentBinding] ?? false)) {
145 145
             $values = $this->query->bindings["where"][$this->currentBinding];
146 146
             $this->currentBinding++;
147 147
 
148 148
             if ($where["type"] === "between") {
149
-                $values .= "_" . $this->query->bindings["where"][$this->currentBinding];
149
+                $values .= "_".$this->query->bindings["where"][$this->currentBinding];
150 150
                 $this->currentBinding++;
151 151
             }
152 152
         }
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 
157 157
     protected function getWhereClauses(array $wheres = []) : string
158 158
     {
159
-        return "" . $this->getWheres($wheres)
160
-            ->reduce(function ($carry, $where) {
159
+        return "".$this->getWheres($wheres)
160
+            ->reduce(function($carry, $where) {
161 161
                 $value = $carry;
162 162
                 $value .= $this->getNestedClauses($where);
163 163
                 $value .= $this->getColumnClauses($where);
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 
173 173
     protected function getNestedClauses(array $where) : string
174 174
     {
175
-        if (! in_array($where["type"], ["Exists", "Nested", "NotExists"])) {
175
+        if (!in_array($where["type"], ["Exists", "Nested", "NotExists"])) {
176 176
             return "";
177 177
         }
178 178
 
179
-        return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres);
179
+        return "-".strtolower($where["type"]).$this->getWhereClauses($where["query"]->wheres);
180 180
     }
181 181
 
182 182
     protected function getColumnClauses(array $where) : string
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 
191 191
     protected function getInClauses(array $where) : string
192 192
     {
193
-        if (! in_array($where["type"], ["In"])) {
193
+        if (!in_array($where["type"], ["In"])) {
194 194
             return "";
195 195
         }
196 196
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 
203 203
     protected function getNotInClauses(array $where) : string
204 204
     {
205
-        if (! in_array($where["type"], ["NotIn"])) {
205
+        if (!in_array($where["type"], ["NotIn"])) {
206 206
             return "";
207 207
         }
208 208
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
                 continue;
224 224
             }
225 225
 
226
-            $result .= $glue . $value;
226
+            $result .= $glue.$value;
227 227
         }
228 228
 
229 229
         return $result;
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
         $clause = "_{$where["boolean"]}";
240 240
 
241 241
         while (count($queryParts) > 1) {
242
-            $clause .= "_" . array_shift($queryParts);
242
+            $clause .= "_".array_shift($queryParts);
243 243
             $clause .= $this->query->bindings["where"][$this->currentBinding];
244 244
             $this->currentBinding++;
245 245
         }
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
         $lastPart = array_shift($queryParts);
248 248
 
249 249
         if ($lastPart) {
250
-            $clause .= "_" . $lastPart;
250
+            $clause .= "_".$lastPart;
251 251
         }
252 252
 
253
-        return "-" . str_replace(" ", "_", $clause);
253
+        return "-".str_replace(" ", "_", $clause);
254 254
     }
255 255
 
256 256
     protected function getOtherClauses(array $where) : string
@@ -284,6 +284,6 @@  discard block
 block discarded – undo
284 284
             return "";
285 285
         }
286 286
 
287
-        return "-" . implode("-", $eagerLoads->keys()->toArray());
287
+        return "-".implode("-", $eagerLoads->keys()->toArray());
288 288
     }
289 289
 }
Please login to merge, or discard this patch.
src/Traits/ModelCaching.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,22 +18,22 @@  discard block
 block discarded – undo
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::created(function ($instance) {
28
+        static::created(function($instance) {
29 29
             $instance->checkCooldownAndFlushAfterPersisting($instance);
30 30
         });
31 31
 
32
-        static::deleted(function ($instance) {
32
+        static::deleted(function($instance) {
33 33
             $instance->checkCooldownAndFlushAfterPersisting($instance);
34 34
         });
35 35
 
36
-        static::saved(function ($instance) {
36
+        static::saved(function($instance) {
37 37
             $instance->checkCooldownAndFlushAfterPersisting($instance);
38 38
         });
39 39
 
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
         //     $instance->checkCooldownAndFlushAfterPersisting($instance);
43 43
         // });
44 44
 
45
-        static::pivotAttached(function ($instance) {
45
+        static::pivotAttached(function($instance) {
46 46
             $instance->checkCooldownAndFlushAfterPersisting($instance);
47 47
         });
48 48
 
49
-        static::pivotDetached(function ($instance) {
49
+        static::pivotDetached(function($instance) {
50 50
             $instance->checkCooldownAndFlushAfterPersisting($instance);
51 51
         });
52 52
 
53
-        static::pivotUpdated(function ($instance) {
53
+        static::pivotUpdated(function($instance) {
54 54
             $instance->checkCooldownAndFlushAfterPersisting($instance);
55 55
         });
56 56
     }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 
67 67
     public function newEloquentBuilder($query)
68 68
     {
69
-        if (! $this->isCachable()) {
69
+        if (!$this->isCachable()) {
70 70
             $this->isCachable = true;
71 71
 
72 72
             return new EloquentBuilder($query);
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
         $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds";
94 94
 
95 95
         $this->cache()
96
-            ->rememberForever($cacheKey, function () use ($seconds) {
96
+            ->rememberForever($cacheKey, function() use ($seconds) {
97 97
                 return $seconds;
98 98
             });
99 99
 
100 100
         $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at";
101 101
         $this->cache()
102
-            ->rememberForever($cacheKey, function () {
102
+            ->rememberForever($cacheKey, function() {
103 103
                 return (new Carbon)->now();
104 104
             });
105 105
 
Please login to merge, or discard this patch.