@@ -66,7 +66,7 @@ discard block |
||
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 |
||
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 | }) |
@@ -26,13 +26,13 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | }) |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | public function increment(string $key, int $value, $member = null): bool |
33 | 33 | { |
34 | - if (! empty($member) || is_numeric($member)) { |
|
35 | - $this->connection->zincrby($this->prefix.$key, $value, $member); |
|
34 | + if (!empty($member) || is_numeric($member)) { |
|
35 | + $this->connection->zincrby($this->prefix . $key, $value, $member); |
|
36 | 36 | } else { |
37 | - $this->connection->incrby($this->prefix.$key, $value); |
|
37 | + $this->connection->incrby($this->prefix . $key, $value); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | // both methods returns integer and raise an exception in case of an error. |
@@ -48,35 +48,35 @@ discard block |
||
48 | 48 | |
49 | 49 | public function delete($key, $member = null): bool |
50 | 50 | { |
51 | - if(is_array($key)) { |
|
51 | + if (is_array($key)) { |
|
52 | 52 | array_walk($key, function($item) { |
53 | 53 | $this->delete($item); |
54 | 54 | }); |
55 | 55 | return true; |
56 | 56 | } |
57 | 57 | |
58 | - if(! empty($member) || is_numeric($member)) { |
|
59 | - return $this->connection->zrem($this->prefix.$key, $member) > 0; |
|
58 | + if (!empty($member) || is_numeric($member)) { |
|
59 | + return $this->connection->zrem($this->prefix . $key, $member) > 0; |
|
60 | 60 | } else { |
61 | - return $this->connection->del($this->prefix.$key) > 0; |
|
61 | + return $this->connection->del($this->prefix . $key) > 0; |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | 65 | public function get(string $key, $member = null) |
66 | 66 | { |
67 | - if(! empty($member) || is_numeric($member)) { |
|
68 | - return $this->connection->zscore($this->prefix.$key, $member); |
|
67 | + if (!empty($member) || is_numeric($member)) { |
|
68 | + return $this->connection->zscore($this->prefix . $key, $member); |
|
69 | 69 | } else { |
70 | - return $this->connection->get($this->prefix.$key); |
|
70 | + return $this->connection->get($this->prefix . $key); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | 74 | public function set(string $key, $value, $member = null): bool |
75 | 75 | { |
76 | - if(! empty($member) || is_numeric($member)) { |
|
77 | - return $this->connection->zAdd($this->prefix.$key, $value, $member) > 0; |
|
76 | + if (!empty($member) || is_numeric($member)) { |
|
77 | + return $this->connection->zAdd($this->prefix . $key, $value, $member) > 0; |
|
78 | 78 | } else { |
79 | - return (bool) $this->connection->set($this->prefix.$key, $value); |
|
79 | + return (bool) $this->connection->set($this->prefix . $key, $value); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
@@ -90,39 +90,39 @@ discard block |
||
90 | 90 | |
91 | 91 | return $item; |
92 | 92 | }, |
93 | - $this->connection->keys($this->prefix.$word) ?? [] |
|
93 | + $this->connection->keys($this->prefix . $word) ?? [] |
|
94 | 94 | ); |
95 | 95 | } |
96 | 96 | |
97 | 97 | public function flatList(string $key, int $limit = -1): array |
98 | 98 | { |
99 | - return $this->connection->lrange($this->prefix.$key, 0, $limit); |
|
99 | + return $this->connection->lrange($this->prefix . $key, 0, $limit); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function addToFlatList(string $key, $value): bool |
103 | 103 | { |
104 | - return $this->connection->rpush($this->prefix.$key, $value) !== false; |
|
104 | + return $this->connection->rpush($this->prefix . $key, $value) !== false; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | public function valueList(string $key, int $limit = -1, bool $orderByAsc = false, bool $withValues = false): array |
108 | 108 | { |
109 | 109 | $range = $orderByAsc ? 'zrange' : 'zrevrange'; |
110 | 110 | |
111 | - return $this->connection->$range($this->prefix.$key, 0, $limit, $this->isPHPRedis ? $withValues : ['withscores' => $withValues]) ?: []; |
|
111 | + return $this->connection->$range($this->prefix . $key, 0, $limit, $this->isPHPRedis ? $withValues : ['withscores' => $withValues]) ?: []; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | public function exists(string $key): bool |
115 | 115 | { |
116 | - return (bool) $this->connection->exists($this->prefix.$key); |
|
116 | + return (bool) $this->connection->exists($this->prefix . $key); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | public function timeLeft(string $key): int |
120 | 120 | { |
121 | - return $this->connection->ttl($this->prefix.$key); |
|
121 | + return $this->connection->ttl($this->prefix . $key); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | public function setExpiration(string $key, int $time): bool |
125 | 125 | { |
126 | - return $this->connection->expire($this->prefix.$key, $time); |
|
126 | + return $this->connection->expire($this->prefix . $key, $time); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | \ No newline at end of file |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | ->connect($this->config['connection']) |
82 | 82 | ->setPrefix($this->config['keys_prefix'] ?? $this->config['redis_keys_prefix'] ?? 'visits'); |
83 | 83 | |
84 | - if(! $this->connection) { |
|
84 | + if (!$this->connection) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | 87 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $this->subject = $subject; |
94 | 94 | $this->keys = new Keys($subject, preg_replace('/[^a-z0-9_]/i', '', $tag)); |
95 | 95 | |
96 | - if (! empty($this->keys->id)) { |
|
96 | + if (!empty($this->keys->id)) { |
|
97 | 97 | $this->periodsSync(); |
98 | 98 | } |
99 | 99 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | 'eloquent' => \Awssat\Visits\DataEngines\EloquentEngine::class |
106 | 106 | ]; |
107 | 107 | |
108 | - if(! array_key_exists($name, $connections)) { |
|
108 | + if (!array_key_exists($name, $connections)) { |
|
109 | 109 | throw new \Exception("(Laravel-Visits) The selected engine `{$name}` is not supported! Please correct this issue from config/visits.php."); |
110 | 110 | } |
111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function by($subject) |
120 | 120 | { |
121 | - if($subject instanceof Model) { |
|
121 | + if ($subject instanceof Model) { |
|
122 | 122 | $this->keys->append($this->keys->modelName($subject), $subject->{$subject->getKeyName()}); |
123 | 123 | } else if (is_array($subject)) { |
124 | 124 | $this->keys->append(array_keys($subject)[0], Arr::first($subject)); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function recordedIp() |
147 | 147 | { |
148 | - if(! $this->connection->exists($this->keys->ip(request()->ip()))) { |
|
148 | + if (!$this->connection->exists($this->keys->ip(request()->ip()))) { |
|
149 | 149 | $this->connection->set($this->keys->ip(request()->ip()), true); |
150 | 150 | $this->connection->setExpiration($this->keys->ip(request()->ip()), $this->ipSeconds); |
151 | 151 | |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | public function count() |
163 | 163 | { |
164 | 164 | if ($this->country) { |
165 | - return $this->connection->get($this->keys->visits."_countries:{$this->keys->id}", $this->country); |
|
165 | + return $this->connection->get($this->keys->visits . "_countries:{$this->keys->id}", $this->country); |
|
166 | 166 | } else if ($this->referer) { |
167 | - return $this->connection->get($this->keys->visits."_referers:{$this->keys->id}", $this->referer); |
|
167 | + return $this->connection->get($this->keys->visits . "_referers:{$this->keys->id}", $this->referer); |
|
168 | 168 | } else if ($this->operatingSystem) { |
169 | - return $this->connection->get($this->keys->visits."_OSes:{$this->keys->id}", $this->operatingSystem); |
|
169 | + return $this->connection->get($this->keys->visits . "_OSes:{$this->keys->id}", $this->operatingSystem); |
|
170 | 170 | } else if ($this->language) { |
171 | - return $this->connection->get($this->keys->visits."_languages:{$this->keys->id}", $this->language); |
|
171 | + return $this->connection->get($this->keys->visits . "_languages:{$this->keys->id}", $this->language); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return intval( |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | $this->connection->increment($this->keys->visits, $inc, $this->keys->id); |
213 | 213 | $this->connection->increment($this->keys->visitsTotal(), $inc); |
214 | 214 | |
215 | - if(is_array($this->globalIgnore) && sizeof($this->globalIgnore) > 0) { |
|
215 | + if (is_array($this->globalIgnore) && sizeof($this->globalIgnore) > 0) { |
|
216 | 216 | $ignore = array_merge($ignore, $this->globalIgnore); |
217 | 217 | } |
218 | 218 | |
219 | 219 | //NOTE: $$method is parameter also .. ($periods,$country,$refer) |
220 | 220 | foreach (['country', 'refer', 'periods', 'operatingSystem', 'language'] as $method) { |
221 | - if(! in_array($method, $ignore)) { |
|
222 | - $this->{'record'.Str::studly($method)}($inc); |
|
221 | + if (!in_array($method, $ignore)) { |
|
222 | + $this->{'record' . Str::studly($method)}($inc); |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
@@ -280,6 +280,6 @@ discard block |
||
280 | 280 | { |
281 | 281 | $prefix = $this->config['keys_prefix'] ?? $this->config['redis_keys_prefix'] ?? 'visits'; |
282 | 282 | |
283 | - return $this->subject->hasOne(Visit::class, 'secondary_key')->where('primary_key', $prefix.':'.$this->keys->visits); |
|
283 | + return $this->subject->hasOne(Visit::class, 'secondary_key')->where('primary_key', $prefix . ':' . $this->keys->visits); |
|
284 | 284 | } |
285 | 285 | } |