Passed
Pull Request — master (#129)
by Andrey
04:19
created
src/Traits/Caching.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at";
49 49
 
50 50
             $this->cache()
51
-                ->rememberForever($cacheKey, function () {
51
+                ->rememberForever($cacheKey, function() {
52 52
                     return now();
53 53
                 });
54 54
         }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         return "genealabs:laravel-model-caching:"
60 60
             . (config('laravel-model-caching.cache-prefix')
61
-                ? config('laravel-model-caching.cache-prefix', '') . ":"
61
+                ? config('laravel-model-caching.cache-prefix', '').":"
62 62
                 : "");
63 63
     }
64 64
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         [$cacheCooldown, $invalidatedAt, $savedAt] = $this
91 91
             ->getCacheCooldownDetails($instance, $cachePrefix, $modelClassName);
92 92
 
93
-        if (! $cacheCooldown || $cacheCooldown === 0) {
93
+        if (!$cacheCooldown || $cacheCooldown === 0) {
94 94
             return [null, null, null];
95 95
         }
96 96
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     {
124 124
         [$cacheCooldown, $invalidatedAt] = $this->getModelCacheCooldown($instance);
125 125
 
126
-        if (! $cacheCooldown
126
+        if (!$cacheCooldown
127 127
             || now()->diffInSeconds($invalidatedAt) < $cacheCooldown
128 128
         ) {
129 129
             return;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     {
149 149
         [$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance);
150 150
 
151
-        if (! $cacheCooldown) {
151
+        if (!$cacheCooldown) {
152 152
             $instance->flushCache();
153 153
 
154 154
             return;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     public function isCachable() : bool
165 165
     {
166 166
         return $this->isCachable
167
-            && ! config('laravel-model-caching.disabled');
167
+            && !config('laravel-model-caching.disabled');
168 168
     }
169 169
 
170 170
     protected function setCacheCooldownSavedAtTimestamp(Model $instance)
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:saved-at";
175 175
 
176 176
         $instance->cache()
177
-            ->rememberForever($cacheKey, function () {
177
+            ->rememberForever($cacheKey, function() {
178 178
                 return now();
179 179
             });
180 180
     }
Please login to merge, or discard this patch.
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/ModelCaching.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,29 +17,29 @@  discard block
 block discarded – undo
17 17
         $key = $instance->makeCacheKey();
18 18
 
19 19
         return $instance->cache($tags)
20
-            ->rememberForever($key, function () use ($columns) {
20
+            ->rememberForever($key, function() use ($columns) {
21 21
                 return parent::all($columns);
22 22
             });
23 23
     }
24 24
 
25 25
     public static function bootCachable()
26 26
     {
27
-        static::deleted(function ($instance) {
27
+        static::deleted(function($instance) {
28 28
             $instance->checkCooldownAndFlushAfterPersiting($instance);
29 29
         });
30
-        static::saved(function ($instance) {
30
+        static::saved(function($instance) {
31 31
             $instance->checkCooldownAndFlushAfterPersiting($instance);
32 32
         });
33 33
 
34
-        static::pivotAttached(function ($instance) {
34
+        static::pivotAttached(function($instance) {
35 35
             $instance->checkCooldownAndFlushAfterPersiting($instance);
36 36
         });
37 37
 
38
-        static::pivotDetached(function ($instance) {
38
+        static::pivotDetached(function($instance) {
39 39
             $instance->checkCooldownAndFlushAfterPersiting($instance);
40 40
         });
41 41
 
42
-        static::pivotUpdated(function ($instance) {
42
+        static::pivotUpdated(function($instance) {
43 43
             $instance->checkCooldownAndFlushAfterPersiting($instance);
44 44
         });
45 45
     }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
     public function newEloquentBuilder($query)
57 57
     {
58
-        if (! $this->isCachable()) {
58
+        if (!$this->isCachable()) {
59 59
             $this->isCachable = true;
60 60
 
61 61
             return new EloquentBuilder($query);
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
         $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:seconds";
83 83
 
84 84
         $this->cache()
85
-            ->rememberForever($cacheKey, function () use ($seconds) {
85
+            ->rememberForever($cacheKey, function() use ($seconds) {
86 86
                 return $seconds;
87 87
             });
88 88
 
89 89
         $cacheKey = "{$cachePrefix}:{$modelClassName}-cooldown:invalidated-at";
90 90
         $this->cache()
91
-            ->rememberForever($cacheKey, function () {
91
+            ->rememberForever($cacheKey, function() {
92 92
                 return now();
93 93
             });
94 94
 
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/CachedBuilder.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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),
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/CacheKey.php 1 patch
Spacing   +19 added lines, -19 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,12 +92,12 @@  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
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,13 +115,13 @@  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
122 122
     {
123 123
         if (is_array(array_get($where, "values"))) {
124
-            return implode("_", array_map(function ($key, $value) {
124
+            return implode("_", array_map(function($key, $value) {
125 125
                 if (is_array($value)) {
126 126
                     return implode("_", $value + [$key]);
127 127
                 }
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 
136 136
     protected function getValuesFromBindings(array $where, string $values) : string
137 137
     {
138
-        if (! $values && ($this->query->bindings["where"] ?? false)) {
138
+        if (!$values && ($this->query->bindings["where"] ?? false)) {
139 139
             $values = $this->query->bindings["where"][$this->currentBinding];
140 140
             $this->currentBinding++;
141 141
 
142 142
             if ($where["type"] === "between") {
143
-                $values .= "_" . $this->query->bindings["where"][$this->currentBinding];
143
+                $values .= "_".$this->query->bindings["where"][$this->currentBinding];
144 144
                 $this->currentBinding++;
145 145
             }
146 146
         }
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 
151 151
     protected function getWhereClauses(array $wheres = []) : string
152 152
     {
153
-        return "" . $this->getWheres($wheres)
154
-            ->reduce(function ($carry, $where) {
153
+        return "".$this->getWheres($wheres)
154
+            ->reduce(function($carry, $where) {
155 155
                 $value = $carry;
156 156
                 $value .= $this->getNestedClauses($where);
157 157
                 $value .= $this->getColumnClauses($where);
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 
165 165
     protected function getNestedClauses(array $where) : string
166 166
     {
167
-        if (! in_array($where["type"], ["Exists", "Nested", "NotExists"])) {
167
+        if (!in_array($where["type"], ["Exists", "Nested", "NotExists"])) {
168 168
             return "";
169 169
         }
170 170
 
171 171
         $this->currentBinding++;
172 172
 
173
-        return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres);
173
+        return "-".strtolower($where["type"]).$this->getWhereClauses($where["query"]->wheres);
174 174
     }
175 175
 
176 176
     protected function getColumnClauses(array $where) : string
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         $clause = "_{$where["boolean"]}";
195 195
 
196 196
         while (count($queryParts) > 1) {
197
-            $clause .= "_" . array_shift($queryParts);
197
+            $clause .= "_".array_shift($queryParts);
198 198
             $clause .= $this->query->bindings["where"][$this->currentBinding];
199 199
             $this->currentBinding++;
200 200
         }
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
         $lastPart = array_shift($queryParts);
203 203
 
204 204
         if ($lastPart) {
205
-            $clause .= "_" . $lastPart;
205
+            $clause .= "_".$lastPart;
206 206
         }
207 207
 
208
-        return "-" . str_replace(" ", "_", $clause);
208
+        return "-".str_replace(" ", "_", $clause);
209 209
     }
210 210
 
211 211
     protected function getOtherClauses(array $where, string $carry = null) : string
@@ -239,6 +239,6 @@  discard block
 block discarded – undo
239 239
             return "";
240 240
         }
241 241
 
242
-        return "-" . implode("-", $eagerLoads->keys()->toArray());
242
+        return "-".implode("-", $eagerLoads->keys()->toArray());
243 243
     }
244 244
 }
Please login to merge, or discard this patch.