Passed
Pull Request — master (#58)
by
unknown
04:55
created
src/DataEngines/EloquentEngine.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     public function get(string $key, $member = null)
67 67
     {
68 68
         if(! empty($member) || is_numeric($member)) {
69
-             return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => $member])
69
+                return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => $member])
70 70
             ->where(function($q) {
71 71
                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
72 72
             })
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     {
194 194
         $time = \Carbon\Carbon::now()->addSeconds($time);
195 195
 
196
-         return $this->model->where(['primary_key' => $this->prefix.$key])
196
+            return $this->model->where(['primary_key' => $this->prefix.$key])
197 197
                             ->where(function($q) {
198 198
                                 return $q->where('expired_at', '<', \Carbon\Carbon::now())->orWhereNull('expired_at');
199 199
                             })
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
 
27 27
     public function increment(string $key, int $value, $member = null): bool
28 28
     {
29
-        if (! empty($member) || is_numeric($member)) {
30
-            $row = $this->model->firstOrNew(['primary_key' => $this->prefix.$key, 'secondary_key' => $member]);
29
+        if (!empty($member) || is_numeric($member)) {
30
+            $row = $this->model->firstOrNew(['primary_key' => $this->prefix . $key, 'secondary_key' => $member]);
31 31
         } else {
32
-            $row = $this->model->firstOrNew(['primary_key' => $this->prefix.$key, 'secondary_key' => null]);
32
+            $row = $this->model->firstOrNew(['primary_key' => $this->prefix . $key, 'secondary_key' => null]);
33 33
         }
34 34
    
35
-        if($row->expired_at !== null && \Carbon\Carbon::now()->gt($row->expired_at)) {
35
+        if ($row->expired_at !== null && \Carbon\Carbon::now()->gt($row->expired_at)) {
36 36
             $row->score = $value;
37 37
             $row->expired_at = null;
38 38
         } else {
@@ -49,30 +49,30 @@  discard block
 block discarded – undo
49 49
 
50 50
     public function delete($key, $member = null): bool
51 51
     {
52
-        if(is_array($key)) {
52
+        if (is_array($key)) {
53 53
             array_walk($key, function($item) {
54 54
                 $this->delete($item);
55 55
             });
56 56
             return true;
57 57
         }
58 58
 
59
-        if(! empty($member) || is_numeric($member)) {
60
-            return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => $member])->delete();
59
+        if (!empty($member) || is_numeric($member)) {
60
+            return $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => $member])->delete();
61 61
         } else {
62
-            return $this->model->where(['primary_key' => $this->prefix.$key])->delete();
62
+            return $this->model->where(['primary_key' => $this->prefix . $key])->delete();
63 63
         }
64 64
     }
65 65
 
66 66
     public function get(string $key, $member = null)
67 67
     {
68
-        if(! empty($member) || is_numeric($member)) {
69
-             return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => $member])
68
+        if (!empty($member) || is_numeric($member)) {
69
+             return $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => $member])
70 70
             ->where(function($q) {
71 71
                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
72 72
             })
73 73
             ->value('score');
74 74
         } else {
75
-            return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => null])
75
+            return $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => null])
76 76
             ->where(function($q) {
77 77
                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
78 78
             })
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 
83 83
     public function set(string $key, $value, $member = null): bool
84 84
     {
85
-        if(! empty($member) || is_numeric($member)) {
85
+        if (!empty($member) || is_numeric($member)) {
86 86
             return $this->model->updateOrCreate([
87
-                'primary_key' => $this->prefix.$key, 
87
+                'primary_key' => $this->prefix . $key, 
88 88
                 'secondary_key' => $member,
89 89
                 'score' => $value,
90 90
                 ]) instanceof Model;
91 91
         } else {
92 92
             return $this->model->updateOrCreate([
93
-                'primary_key' => $this->prefix.$key, 
93
+                'primary_key' => $this->prefix . $key, 
94 94
                 'score' => $value,
95 95
                 ]) instanceof Model;
96 96
         }
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
     {
101 101
         $results = [];
102 102
 
103
-        if($word == '*') {
103
+        if ($word == '*') {
104 104
             $results = $this->model
105 105
                         ->where(function($q) {
106 106
                             return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
107 107
                         })
108 108
                         ->pluck('primary_key');
109 109
         } else {
110
-            $results = $this->model->where('primary_key', 'like', $this->prefix.str_replace('*', '%', $word))
110
+            $results = $this->model->where('primary_key', 'like', $this->prefix . str_replace('*', '%', $word))
111 111
                                 ->where(function($q) {
112 112
                                     return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
113 113
                                 })
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     public function flatList(string $key, int $limit = -1): array
130 130
     {
131 131
         return array_slice(
132
-            $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => null])
132
+            $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => null])
133 133
                         ->where(function($q) {
134 134
                             return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
135 135
                         })
@@ -139,22 +139,22 @@  discard block
 block discarded – undo
139 139
 
140 140
     public function addToFlatList(string $key, $value): bool
141 141
     {
142
-        $row = $this->model->firstOrNew(['primary_key' => $this->prefix.$key, 'secondary_key' => null]);
142
+        $row = $this->model->firstOrNew(['primary_key' => $this->prefix . $key, 'secondary_key' => null]);
143 143
 
144
-        if($row->expired_at !== null && \Carbon\Carbon::now()->gt($row->expired_at)) {
144
+        if ($row->expired_at !== null && \Carbon\Carbon::now()->gt($row->expired_at)) {
145 145
             $row->list = (array) $value;
146 146
             $row->expired_at = null;
147 147
         } else {
148 148
             $row->list = array_merge($row->list ?? [], (array) $value);
149 149
         }
150 150
 
151
-        $row->score =  $row->score ?? 0;
151
+        $row->score = $row->score ?? 0;
152 152
         return (bool) $row->save();
153 153
     }
154 154
 
155 155
     public function valueList(string $key, int $limit = -1, bool $orderByAsc = false, bool $withValues = false): array
156 156
     {
157
-        $rows = $this->model->where('primary_key', $this->prefix.$key)
157
+        $rows = $this->model->where('primary_key', $this->prefix . $key)
158 158
                             ->where(function($q) {
159 159
                                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
160 160
                             })
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
                             ->whereNotNull('secondary_key')
163 163
                             ->orderBy('score', $orderByAsc ? 'asc' : 'desc')
164 164
                             ->when($limit > -1, function($q) use($limit) {
165
-                                return $q->limit($limit+1);
165
+                                return $q->limit($limit + 1);
166 166
                             })->pluck('score', 'secondary_key') ?? \Illuminate\Support\Collection::make();
167 167
 
168 168
         return $withValues ? $rows->toArray() : array_keys($rows->toArray());
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 
171 171
     public function exists(string $key): bool
172 172
     {
173
-        return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => null])
173
+        return $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => null])
174 174
                             ->where(function($q) {
175 175
                                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
176 176
                             })
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 
180 180
     public function timeLeft(string $key): int
181 181
     {
182
-        $expired_at = $this->model->where(['primary_key' => $this->prefix.$key])->value('expired_at');
182
+        $expired_at = $this->model->where(['primary_key' => $this->prefix . $key])->value('expired_at');
183 183
 
184
-        if($expired_at === null) {
184
+        if ($expired_at === null) {
185 185
             return -2;
186 186
         }
187 187
 
188
-        $ttl =  $expired_at->timestamp - \Carbon\Carbon::now()->timestamp;
188
+        $ttl = $expired_at->timestamp - \Carbon\Carbon::now()->timestamp;
189 189
         return $ttl <= 0 ? -1 : $ttl;
190 190
     }
191 191
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     {
194 194
         $time = \Carbon\Carbon::now()->addSeconds($time);
195 195
 
196
-         return $this->model->where(['primary_key' => $this->prefix.$key])
196
+         return $this->model->where(['primary_key' => $this->prefix . $key])
197 197
                             ->where(function($q) {
198 198
                                 return $q->where('expired_at', '<', \Carbon\Carbon::now())->orWhereNull('expired_at');
199 199
                             })
Please login to merge, or discard this patch.