Passed
Push — master ( 328eca...a3f109 )
by
unknown
04:31
created
src/Keys.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function visits()
35 35
     {
36
-        return (app()->environment('testing') ? 'testing:' : '').$this->modelName."_{$this->tag}";
36
+        return (app()->environment('testing') ? 'testing:' : '') . $this->modelName . "_{$this->tag}";
37 37
     }
38 38
 
39 39
     /**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function ip($ip)
51 51
     {
52
-        return $this->visits.'_'.Str::snake(
53
-            'recorded_ips:'.($this->instanceOfModel ? "{$this->id}:" : '') . $ip
52
+        return $this->visits . '_' . Str::snake(
53
+            'recorded_ips:' . ($this->instanceOfModel ? "{$this->id}:" : '') . $ip
54 54
         );
55 55
     }
56 56
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function cache($limit = '*', $isLow = false, $constraints = [])
61 61
     {
62
-        $key = $this->visits.'_lists';
62
+        $key = $this->visits . '_lists';
63 63
 
64 64
         if ($limit == '*') {
65 65
             return "{$key}:*";
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 
68 68
         //it might not be that unique but it does the job since not many lists
69 69
         //will be generated to one key.
70
-        $constraintsPart = count($constraints) ? ':'.substr(sha1(serialize($constraints)), 0, 7) : '';
70
+        $constraintsPart = count($constraints) ? ':' . substr(sha1(serialize($constraints)), 0, 7) : '';
71 71
 
72
-        return "{$key}:".($isLow ? 'low' : 'top').$constraintsPart.$limit;
72
+        return "{$key}:" . ($isLow ? 'low' : 'top') . $constraintsPart . $limit;
73 73
     }
74 74
 
75 75
     /**
Please login to merge, or discard this patch.
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
             })
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     {
196 196
         // $time = \Carbon\Carbon::now()->addSeconds($time);
197 197
 
198
-         return $this->model->where(['primary_key' => $this->prefix.$key])
198
+            return $this->model->where(['primary_key' => $this->prefix.$key])
199 199
                                 ->where(function($q) {
200 200
                                     return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
201 201
                                 })
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,16 +82,16 @@  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
                 'expired_at' => null,
91 91
                 ]) instanceof Model;
92 92
         } else {
93 93
             return $this->model->updateOrCreate([
94
-                'primary_key' => $this->prefix.$key, 
94
+                'primary_key' => $this->prefix . $key, 
95 95
                 'score' => $value,
96 96
                 'expired_at' => null,
97 97
                 ]) instanceof Model;
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
     {
103 103
         $results = [];
104 104
 
105
-        if($word == '*') {
105
+        if ($word == '*') {
106 106
             $results = $this->model
107 107
                         ->where(function($q) {
108 108
                             return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
109 109
                         })
110 110
                         ->pluck('primary_key');
111 111
         } else {
112
-            $results = $this->model->where('primary_key', 'like', $this->prefix.str_replace('*', '%', $word))
112
+            $results = $this->model->where('primary_key', 'like', $this->prefix . str_replace('*', '%', $word))
113 113
                                 ->where(function($q) {
114 114
                                     return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
115 115
                                 })
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     public function flatList(string $key, int $limit = -1): array
132 132
     {
133 133
         return array_slice(
134
-            $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => null])
134
+            $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => null])
135 135
                         ->where(function($q) {
136 136
                             return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
137 137
                         })
@@ -141,22 +141,22 @@  discard block
 block discarded – undo
141 141
 
142 142
     public function addToFlatList(string $key, $value): bool
143 143
     {
144
-        $row = $this->model->firstOrNew(['primary_key' => $this->prefix.$key, 'secondary_key' => null]);
144
+        $row = $this->model->firstOrNew(['primary_key' => $this->prefix . $key, 'secondary_key' => null]);
145 145
 
146
-        if($row->expired_at !== null && \Carbon\Carbon::now()->gt($row->expired_at)) {
146
+        if ($row->expired_at !== null && \Carbon\Carbon::now()->gt($row->expired_at)) {
147 147
             $row->list = (array) $value;
148 148
             $row->expired_at = null;
149 149
         } else {
150 150
             $row->list = array_merge($row->list ?? [], (array) $value);
151 151
         }
152 152
 
153
-        $row->score =  $row->score ?? 0;
153
+        $row->score = $row->score ?? 0;
154 154
         return (bool) $row->save();
155 155
     }
156 156
 
157 157
     public function valueList(string $key, int $limit = -1, bool $orderByAsc = false, bool $withValues = false): array
158 158
     {
159
-        $rows = $this->model->where('primary_key', $this->prefix.$key)
159
+        $rows = $this->model->where('primary_key', $this->prefix . $key)
160 160
                             ->where(function($q) {
161 161
                                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
162 162
                             })
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                             ->whereNotNull('secondary_key')
165 165
                             ->orderBy('score', $orderByAsc ? 'asc' : 'desc')
166 166
                             ->when($limit > -1, function($q) use($limit) {
167
-                                return $q->limit($limit+1);
167
+                                return $q->limit($limit + 1);
168 168
                             })->pluck('score', 'secondary_key') ?? \Illuminate\Support\Collection::make();
169 169
 
170 170
         return $withValues ? $rows->toArray() : array_keys($rows->toArray());
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 
173 173
     public function exists(string $key): bool
174 174
     {
175
-        return $this->model->where(['primary_key' => $this->prefix.$key, 'secondary_key' => null])
175
+        return $this->model->where(['primary_key' => $this->prefix . $key, 'secondary_key' => null])
176 176
                             ->where(function($q) {
177 177
                                 return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
178 178
                             })
@@ -181,13 +181,13 @@  discard block
 block discarded – undo
181 181
 
182 182
     public function timeLeft(string $key): int
183 183
     {
184
-        $expired_at = $this->model->where(['primary_key' => $this->prefix.$key])->value('expired_at');
184
+        $expired_at = $this->model->where(['primary_key' => $this->prefix . $key])->value('expired_at');
185 185
 
186
-        if($expired_at === null) {
186
+        if ($expired_at === null) {
187 187
             return -2;
188 188
         }
189 189
 
190
-        $ttl =  $expired_at->timestamp - \Carbon\Carbon::now()->timestamp;
190
+        $ttl = $expired_at->timestamp - \Carbon\Carbon::now()->timestamp;
191 191
         return $ttl <= 0 ? -1 : $ttl;
192 192
     }
193 193
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     {
196 196
         // $time = \Carbon\Carbon::now()->addSeconds($time);
197 197
 
198
-         return $this->model->where(['primary_key' => $this->prefix.$key])
198
+         return $this->model->where(['primary_key' => $this->prefix . $key])
199 199
                                 ->where(function($q) {
200 200
                                     return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at');
201 201
                                 })
Please login to merge, or discard this patch.