@@ -281,13 +281,13 @@ |
||
281 | 281 | foreach ($criterias as $crit) { |
282 | 282 | switch ($crit['condition']) { |
283 | 283 | case '>=': |
284 | - $queryParts[] = $crit['property'] . ':[' . $crit['value'] . ' TO *]'; |
|
284 | + $queryParts[] = $crit['property'].':['.$crit['value'].' TO *]'; |
|
285 | 285 | break; |
286 | 286 | case '<=': |
287 | - $queryParts[] = $crit['property'] . ':[* TO ' . $crit['value'] . ']'; |
|
287 | + $queryParts[] = $crit['property'].':[* TO '.$crit['value'].']'; |
|
288 | 288 | break; |
289 | 289 | case '=': |
290 | - $queryParts[] = $crit['property'] . ':"' . $crit['value'] . '"'; |
|
290 | + $queryParts[] = $crit['property'].':"'.$crit['value'].'"'; |
|
291 | 291 | break; |
292 | 292 | case 'MATCHES': |
293 | 293 | $queryParts[] = $crit['value']; |
@@ -62,9 +62,9 @@ |
||
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | - if (! empty($criterias)) { |
|
65 | + if (!empty($criterias)) { |
|
66 | 66 | $result = $this->get(); |
67 | - if (! empty($result)) { |
|
67 | + if (!empty($result)) { |
|
68 | 68 | return true; |
69 | 69 | } |
70 | 70 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | |
13 | 13 | namespace Localgod\Tick; |
14 | 14 | |
15 | - use RuntimeException; |
|
16 | - use InvalidArgumentException; |
|
17 | - use Localgod\Tick\Entity; |
|
18 | - use Localgod\Tick\Storage\Storage; |
|
15 | + use RuntimeException; |
|
16 | + use InvalidArgumentException; |
|
17 | + use Localgod\Tick\Entity; |
|
18 | + use Localgod\Tick\Storage\Storage; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Record |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getStorage(): Storage |
44 | 44 | { |
45 | - if (! $this->storage instanceof Storage) { |
|
45 | + if (!$this->storage instanceof Storage) { |
|
46 | 46 | $this->storage = Manager::getStorage($this->getConnectionName()); |
47 | 47 | } |
48 | 48 | return $this->storage; |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | { |
64 | 64 | $data = array(); |
65 | 65 | foreach ($this->listPropertyNames() as $property) { |
66 | - if ($this->$property === null && ! $this->notNull($property) && ! $insert) { |
|
67 | - throw new RuntimeException('Property "' . $property . '" can not be persisted as null'); |
|
66 | + if ($this->$property === null && !$this->notNull($property) && !$insert) { |
|
67 | + throw new RuntimeException('Property "'.$property.'" can not be persisted as null'); |
|
68 | 68 | } |
69 | 69 | $data[$this->propertyAlias($property)] = array( |
70 | 70 | 'type' => $this->propertyType($property), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | { |
125 | 125 | $result = array(); |
126 | 126 | foreach ($criterias as $criteria) { |
127 | - if (! $this->propertyExists($criteria['property'])) { |
|
127 | + if (!$this->propertyExists($criteria['property'])) { |
|
128 | 128 | throw new InvalidArgumentException('Unknown property used in get argument.'); |
129 | 129 | } |
130 | 130 | $result[] = array( |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getConnectionName(): string |
82 | 82 | { |
83 | - if (! key_exists(get_class($this), self::$connectionNameMap)) { |
|
83 | + if (!key_exists(get_class($this), self::$connectionNameMap)) { |
|
84 | 84 | $regExp = '/@connection[[:blank:]]+([a-zA-Z0-9_]+)/'; |
85 | 85 | $matches = array(); |
86 | 86 | if (preg_match($regExp, $this->getClassComment(), $matches)) { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getCollectionName(): string |
115 | 115 | { |
116 | - if (! key_exists(get_class($this), self::$collectionNameMap)) { |
|
116 | + if (!key_exists(get_class($this), self::$collectionNameMap)) { |
|
117 | 117 | $regExp = '/@collection[[:blank:]]+([a-zA-Z0-9_]+)/'; |
118 | 118 | $matches = array(); |
119 | 119 | if (preg_match($regExp, $this->getClassComment(), $matches)) { |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | if (in_array($name, $this->listPropertyNames())) { |
215 | 215 | return $this->$name; |
216 | 216 | } |
217 | - throw new Exception('Tried to access unknown property: ' . $name); |
|
217 | + throw new Exception('Tried to access unknown property: '.$name); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | if (is_object($this->$property) && get_class($this->$property) == 'DateTime') { |
233 | 233 | $date = $this->$property; |
234 | 234 | $date->format('Y-m-d H:i:s'); |
235 | - $out .= $property . ' => ' . $date->format('Y-m-d H:i:s'); |
|
235 | + $out .= $property.' => '.$date->format('Y-m-d H:i:s'); |
|
236 | 236 | } else { |
237 | - $out .= $property . ' => ' . $this->$property; |
|
237 | + $out .= $property.' => '.$this->$property; |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | return $out; |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | { |
255 | 255 | $propertyName = lcfirst(str_replace('get', '', $name)); |
256 | 256 | |
257 | - if (! $this->propertyExists($propertyName)) { |
|
258 | - $message = 'Call to undefined method ' . get_class($this) . '::' . $name; |
|
257 | + if (!$this->propertyExists($propertyName)) { |
|
258 | + $message = 'Call to undefined method '.get_class($this).'::'.$name; |
|
259 | 259 | throw new BadMethodCallException($message); |
260 | 260 | } |
261 | 261 | |
262 | 262 | if (sizeof($arguments) != 0) { |
263 | - $message = 'Method ' . get_class($this) . '::' . $name . ' does not take any arguments'; |
|
263 | + $message = 'Method '.get_class($this).'::'.$name.' does not take any arguments'; |
|
264 | 264 | throw new InvalidArgumentException($message); |
265 | 265 | } |
266 | 266 | |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | { |
300 | 300 | $propertyName = lcfirst(str_replace('set', '', $name)); |
301 | 301 | |
302 | - if (! $this->propertyExists($propertyName)) { |
|
303 | - $message = 'Call to undefined method ' . get_class($this) . '::' . $name; |
|
302 | + if (!$this->propertyExists($propertyName)) { |
|
303 | + $message = 'Call to undefined method '.get_class($this).'::'.$name; |
|
304 | 304 | throw new BadMethodCallException($message); |
305 | 305 | } |
306 | 306 | |
307 | 307 | if (sizeof($arguments) != 1) { |
308 | - $message = 'Method ' . get_class($this) . '::' . $name . ' takes only one arguments'; |
|
308 | + $message = 'Method '.get_class($this).'::'.$name.' takes only one arguments'; |
|
309 | 309 | throw new InvalidArgumentException($message); |
310 | 310 | } |
311 | 311 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * |
394 | 394 | * @return string |
395 | 395 | */ |
396 | - protected function getProperty(string $name, string $key): string|null |
|
396 | + protected function getProperty(string $name, string $key): string | null |
|
397 | 397 | { |
398 | 398 | $prop = $this->getMetadata(); |
399 | 399 | if (key_exists($key, $prop["properties"][$name])) { |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | if (key_exists("property", $prop["fields"][$field])) { |
432 | 432 | return $prop["fields"][$field]["property"]; |
433 | 433 | } |
434 | - throw new RuntimeException('Field "' . $field . '" has no property match'); |
|
434 | + throw new RuntimeException('Field "'.$field.'" has no property match'); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | $size = $this->getProperty($name, "size"); |
465 | 465 | if (isset($size) && $size > 0) { |
466 | 466 | if (strlen($value) > $size) { |
467 | - $message = 'Should be in the range 0-' . $size . ' characters. Was ' . strlen($value) . '.'; |
|
467 | + $message = 'Should be in the range 0-'.$size.' characters. Was '.strlen($value).'.'; |
|
468 | 468 | throw new RangeException($message); |
469 | 469 | } |
470 | 470 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | public function getMetadata(): array |
496 | 496 | { |
497 | 497 | $class = get_class($this); |
498 | - if (! key_exists($class, self::$propertyMap)) { |
|
498 | + if (!key_exists($class, self::$propertyMap)) { |
|
499 | 499 | $properties = array(); |
500 | 500 | $propertyBasePattern = '/.*@property\s+([a-zA-Z0-9]+)(?:\(([0-9]+)\))?\s+([_a-zA-Z0-9]+)/'; |
501 | 501 | $optionsPattern = '/(?P<default><[^>]+>)|(?P<options>[a-z]+)/'; |
@@ -526,13 +526,13 @@ discard block |
||
526 | 526 | |
527 | 527 | if (preg_match_all($optionsPattern, $rest, $matches, PREG_PATTERN_ORDER)) { |
528 | 528 | foreach ($matches["default"] as $option) { |
529 | - if (! empty($option)) { |
|
529 | + if (!empty($option)) { |
|
530 | 530 | $property["default"] = substr($option, 1, - 1); |
531 | 531 | break; |
532 | 532 | } |
533 | 533 | } |
534 | 534 | foreach ($matches["options"] as $option) { |
535 | - if (! empty($option)) { |
|
535 | + if (!empty($option)) { |
|
536 | 536 | if ( |
537 | 537 | in_array($option, array( |
538 | 538 | "null", |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | protected function isValidType(string $property, mixed $value): bool |
49 | 49 | { |
50 | 50 | $type = $this->propertyType($property); |
51 | - $value = is_numeric($value) ? $value + 1 - 1 : $value;//Force to be a number |
|
51 | + $value = is_numeric($value) ? $value + 1 - 1 : $value; //Force to be a number |
|
52 | 52 | |
53 | 53 | if ($type == 'integer' && is_numeric($value) && preg_match('/^[0-9]+$/', $value)) { |
54 | 54 | $this->isValidLength($property, $value); |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | } elseif ($value instanceof $type) { |
72 | 72 | return true; |
73 | 73 | } else { |
74 | - $message = 'Input:\'' . $value . '\' of type \'' . gettype($value) . |
|
75 | - '\' does not match property declartion [' . $type . ' $' . $property . ']'; |
|
74 | + $message = 'Input:\''.$value.'\' of type \''.gettype($value). |
|
75 | + '\' does not match property declartion ['.$type.' $'.$property.']'; |
|
76 | 76 | throw new InvalidArgumentException($message, 1); |
77 | 77 | } |
78 | 78 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @var PDO |
37 | 37 | */ |
38 | - private PDO|null $connection; |
|
38 | + private PDO | null $connection; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Set the database connection |
@@ -98,27 +98,27 @@ discard block |
||
98 | 98 | array $criterias, |
99 | 99 | array $order = array(), |
100 | 100 | bool $direction = true, |
101 | - int|null $limit = null, |
|
102 | - int|null $offset = null |
|
101 | + int | null $limit = null, |
|
102 | + int | null $offset = null |
|
103 | 103 | ): array { |
104 | 104 | |
105 | 105 | if (count($fields) > 0) { |
106 | - $select = "`" . implode("`,`", $fields) . "`"; |
|
106 | + $select = "`".implode("`,`", $fields)."`"; |
|
107 | 107 | } else { |
108 | 108 | $select = '*'; |
109 | 109 | } |
110 | 110 | $sql = "SELECT $select |
111 | - FROM `" . $collection . "` " . |
|
112 | - $this->prepareCriteria($criterias) . " " . |
|
113 | - $this->orderBy($order, $direction) . " " . |
|
114 | - $this->limit($limit, $offset) . ";"; |
|
111 | + FROM `".$collection."` ". |
|
112 | + $this->prepareCriteria($criterias)." ". |
|
113 | + $this->orderBy($order, $direction)." ". |
|
114 | + $this->limit($limit, $offset).";"; |
|
115 | 115 | try { |
116 | 116 | $statement = $this->connection->prepare($sql); |
117 | 117 | $statement->execute($this->criteria($criterias)); |
118 | 118 | return $statement->fetchAll(PDO::FETCH_ASSOC); |
119 | 119 | } catch (PDOException $e) { |
120 | - $message = 'Query : "' . |
|
121 | - self::interpolateQuery($sql, $this->criteria($criterias)) . '" returned error : ' . $e->getMessage(); |
|
120 | + $message = 'Query : "'. |
|
121 | + self::interpolateQuery($sql, $this->criteria($criterias)).'" returned error : '.$e->getMessage(); |
|
122 | 122 | throw new RuntimeException($message); |
123 | 123 | } |
124 | 124 | } |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return string Sql representation of a limit clause |
135 | 135 | */ |
136 | - private function limit(int|null $limit, int|null $offset): string |
|
136 | + private function limit(int | null $limit, int | null $offset): string |
|
137 | 137 | { |
138 | - if (! $offset == null) { |
|
139 | - return 'LIMIT ' . $offset . ',' . $limit; |
|
140 | - } elseif (! $limit == null) { |
|
141 | - return 'LIMIT ' . $limit; |
|
138 | + if (!$offset == null) { |
|
139 | + return 'LIMIT '.$offset.','.$limit; |
|
140 | + } elseif (!$limit == null) { |
|
141 | + return 'LIMIT '.$limit; |
|
142 | 142 | } |
143 | 143 | return ''; |
144 | 144 | } |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | */ |
156 | 156 | private function orderBy(array $order, bool $direction = true): string |
157 | 157 | { |
158 | - if (! empty($order)) { |
|
158 | + if (!empty($order)) { |
|
159 | 159 | $count = count($order); |
160 | 160 | $orderString = array(); |
161 | 161 | $orderString[] = 'ORDER BY'; |
162 | - for ($i = 0; $count > $i; $i++) { |
|
162 | + for ($i = 0; $count > $i; $i ++) { |
|
163 | 163 | if ($i == 0) { |
164 | - $orderString[] = '`' . $order[$i] . '`'; |
|
164 | + $orderString[] = '`'.$order[$i].'`'; |
|
165 | 165 | } else { |
166 | - $orderString[] = ', `' . $order[$i] . '`'; |
|
166 | + $orderString[] = ', `'.$order[$i].'`'; |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | $orderString[] = $direction ? 'ASC' : 'DESC'; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | private function criteria(array $criterias): array |
184 | 184 | { |
185 | 185 | $where = array(); |
186 | - if (! empty($criterias)) { |
|
186 | + if (!empty($criterias)) { |
|
187 | 187 | foreach ($criterias as $criteria) { |
188 | 188 | if ($criteria['value'] instanceof DateTime) { |
189 | 189 | $where[] = $criteria['value']->format(DateTime::ISO8601); |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | */ |
206 | 206 | private function prepareCriteria(array $criterias): string |
207 | 207 | { |
208 | - if (! empty($criterias)) { |
|
208 | + if (!empty($criterias)) { |
|
209 | 209 | $where = array(); |
210 | 210 | $where[] = 'WHERE '; |
211 | 211 | foreach ($criterias as $criteria) { |
212 | 212 | if (sizeof($where) > 1) { |
213 | 213 | $where[] = ' AND '; |
214 | 214 | } |
215 | - $where[] = '`' . $criteria['property'] . '` ' . $criteria['condition'] . ' ?'; |
|
215 | + $where[] = '`'.$criteria['property'].'` '.$criteria['condition'].' ?'; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return implode('', $where); |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | $values[] = $value['value']; |
244 | 244 | } |
245 | 245 | |
246 | - $sql = "INSERT INTO `" . $collection . "` (" . implode(', ', array_keys($data)) . ") |
|
247 | - VALUES (" . implode(', ', array_fill(0, count($data), '?')) . ");"; |
|
246 | + $sql = "INSERT INTO `".$collection."` (".implode(', ', array_keys($data)).") |
|
247 | + VALUES (" . implode(', ', array_fill(0, count($data), '?')).");"; |
|
248 | 248 | |
249 | 249 | try { |
250 | 250 | $statement = $this->connection->prepare($sql); |
251 | 251 | $statement->execute($values); |
252 | 252 | return $this->connection->lastInsertId(); |
253 | 253 | } catch (PDOException $e) { |
254 | - $message = 'Query : "' . self::interpolateQuery($sql, $values) . '" returned error : ' . $e->getMessage(); |
|
254 | + $message = 'Query : "'.self::interpolateQuery($sql, $values).'" returned error : '.$e->getMessage(); |
|
255 | 255 | throw new RuntimeException($message); |
256 | 256 | } |
257 | 257 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | $setString = array(); |
291 | 291 | $values = array(); |
292 | 292 | foreach ($data as $field => $value) { |
293 | - $setString[] = '`' . $field . "` = ?"; |
|
293 | + $setString[] = '`'.$field."` = ?"; |
|
294 | 294 | |
295 | 295 | if ($value['type'] == 'DateTime') { |
296 | 296 | $values[] = self::convertDateTime($value['value']); |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | } |
299 | 299 | $values[] = $value['value']; |
300 | 300 | } |
301 | - $sql = "UPDATE `" . $collection . "` |
|
302 | - SET " . implode(', ', $setString) . " " . $this->prepareCriteria($criterias) . ";"; |
|
301 | + $sql = "UPDATE `".$collection."` |
|
302 | + SET " . implode(', ', $setString)." ".$this->prepareCriteria($criterias).";"; |
|
303 | 303 | $values = array_merge($values, $this->criteria($criterias)); |
304 | 304 | try { |
305 | 305 | $statement = $this->connection->prepare($sql); |
306 | 306 | $statement->execute($values); |
307 | 307 | } catch (PDOException $e) { |
308 | - $message = 'Query : "' . self::interpolateQuery($sql, $values) . '" returned error : ' . $e->getMessage(); |
|
308 | + $message = 'Query : "'.self::interpolateQuery($sql, $values).'" returned error : '.$e->getMessage(); |
|
309 | 309 | throw new RuntimeException($message); |
310 | 310 | } |
311 | 311 | } |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | */ |
324 | 324 | public function remove(string $collection, array $criterias): void |
325 | 325 | { |
326 | - $sql = "DELETE FROM `" . $collection . "` " . $this->prepareCriteria($criterias) . ";"; |
|
326 | + $sql = "DELETE FROM `".$collection."` ".$this->prepareCriteria($criterias).";"; |
|
327 | 327 | try { |
328 | 328 | $statement = $this->connection->prepare($sql); |
329 | 329 | $statement->execute($this->criteria($criterias)); |
330 | 330 | } catch (PDOException $e) { |
331 | - $message = 'Query : "' . |
|
332 | - self::interpolateQuery($sql, $this->criteria($criterias)) . '" returned error : ' . $e->getMessage(); |
|
331 | + $message = 'Query : "'. |
|
332 | + self::interpolateQuery($sql, $this->criteria($criterias)).'" returned error : '.$e->getMessage(); |
|
333 | 333 | throw new RuntimeException($message); |
334 | 334 | } |
335 | 335 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | // build a regular expression for each parameter |
387 | 387 | foreach ($params as $key => $value) { |
388 | 388 | if (is_string($key)) { |
389 | - $keys[] = '/:' . $key . '/'; |
|
389 | + $keys[] = '/:'.$key.'/'; |
|
390 | 390 | } else { |
391 | 391 | $keys[] = '/[?]/'; |
392 | 392 | } |
@@ -49,8 +49,8 @@ |
||
49 | 49 | array $criterias, |
50 | 50 | array $order = array(), |
51 | 51 | bool $direction = true, |
52 | - int|null $limit = null, |
|
53 | - int|null $offset = null |
|
52 | + int | null $limit = null, |
|
53 | + int | null $offset = null |
|
54 | 54 | ): array; |
55 | 55 | |
56 | 56 | /** |
@@ -12,15 +12,15 @@ |
||
12 | 12 | |
13 | 13 | namespace Localgod\Tick\Storage; |
14 | 14 | |
15 | - use MongoDB; |
|
16 | - use MongoId; |
|
17 | - use MongoRegex; |
|
18 | - use MongoConnectionException; |
|
19 | - use MongoCursorTimeoutException; |
|
20 | - use MongoDate; |
|
21 | - use Exception; |
|
22 | - use RuntimeException; |
|
23 | - use DateTime; |
|
15 | + use MongoDB; |
|
16 | + use MongoId; |
|
17 | + use MongoRegex; |
|
18 | + use MongoConnectionException; |
|
19 | + use MongoCursorTimeoutException; |
|
20 | + use MongoDate; |
|
21 | + use Exception; |
|
22 | + use RuntimeException; |
|
23 | + use DateTime; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Tick mongo storage implementation |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | array $criterias, |
93 | 93 | array $order = array(), |
94 | 94 | bool $direction = true, |
95 | - int|null $limit = null, |
|
95 | + int | null $limit = null, |
|
96 | 96 | $offset = null |
97 | 97 | ): array { |
98 | 98 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | } |
133 | 133 | return $result; |
134 | 134 | } catch (MongoConnectionException $e) { |
135 | - throw new RuntimeException('Query : returned error : ' . $e->getMessage()); |
|
135 | + throw new RuntimeException('Query : returned error : '.$e->getMessage()); |
|
136 | 136 | } catch (MongoCursorTimeoutException $e) { |
137 | - throw new RuntimeException('Query : returned error : ' . $e->getMessage()); |
|
137 | + throw new RuntimeException('Query : returned error : '.$e->getMessage()); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | private function criteria(array $criterias): array |
150 | 150 | { |
151 | - if (! empty($criterias)) { |
|
151 | + if (!empty($criterias)) { |
|
152 | 152 | $where = array(); |
153 | 153 | $map = array( |
154 | 154 | '<' => '$lt', |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | } |
166 | 166 | if (array_key_exists($criteria['condition'], $map)) { |
167 | 167 | $where[$criteria['property']] = array( |
168 | - '' . $map[$criteria['condition']] . '' => $value |
|
168 | + ''.$map[$criteria['condition']].'' => $value |
|
169 | 169 | ); |
170 | 170 | } elseif (preg_match('/^like$/i', $criteria['condition'])) { |
171 | - $regxp = '/' . (substr($value, 0, 1) == '%' ? '' : '^') . |
|
172 | - str_replace('%', '', $value) . (substr($value, - 1) == '%' ? '' : '$') . '/i'; |
|
171 | + $regxp = '/'.(substr($value, 0, 1) == '%' ? '' : '^'). |
|
172 | + str_replace('%', '', $value).(substr($value, - 1) == '%' ? '' : '$').'/i'; |
|
173 | 173 | $where[$criteria['property']] = new MongoRegex($regxp); |
174 | 174 | } elseif ($criteria['condition'] == '=') { |
175 | 175 | $where[$criteria['property']] = $value; |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | $mongoCollection = $this->connection->selectCollection($collection); |
221 | 221 | $mongoCollection->insert($setArray); |
222 | 222 | } catch (Exception $e) { |
223 | - echo $e->getMessage() . "\n"; |
|
224 | - echo 'Failed insert in collection > $collection: ' . implode(', ', $setArray) . "\n"; |
|
223 | + echo $e->getMessage()."\n"; |
|
224 | + echo 'Failed insert in collection > $collection: '.implode(', ', $setArray)."\n"; |
|
225 | 225 | } |
226 | 226 | //TODO Verify this |
227 | 227 | return 1; |
@@ -10,11 +10,11 @@ |
||
10 | 10 | * @link https://github.com/localgod/php-tick php-tick |
11 | 11 | */ |
12 | 12 | |
13 | - namespace Localgod\Tick; |
|
13 | + namespace Localgod\Tick; |
|
14 | 14 | |
15 | - use Iterator; |
|
16 | - use DateTime; |
|
17 | - use InvalidArgumentException; |
|
15 | + use Iterator; |
|
16 | + use DateTime; |
|
17 | + use InvalidArgumentException; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Result |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | private function getResult(): array |
113 | 113 | { |
114 | - if (! isset($this->result)) { |
|
114 | + if (!isset($this->result)) { |
|
115 | 115 | $fieldNames = $this->model->listFieldNames(); |
116 | 116 | $this->result = $this->model->getStorage()->get( |
117 | 117 | $this->model->getCollectionName(), |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return Result |
246 | 246 | */ |
247 | - public function orderBy(array|string $properties, bool $direction = true): Result |
|
247 | + public function orderBy(array | string $properties, bool $direction = true): Result |
|
248 | 248 | { |
249 | - if (! is_bool($direction)) { |
|
249 | + if (!is_bool($direction)) { |
|
250 | 250 | throw new InvalidArgumentException('Order direction must be boolean. (true = ascending, false descending)'); |
251 | 251 | } |
252 | 252 | $this->direction = $direction; |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | public function offset(int $offset): Result |
286 | 286 | { |
287 | 287 | $this->offset = $offset; |
288 | - if (! is_numeric($this->limit) && ! $this->limit >= 0) { |
|
288 | + if (!is_numeric($this->limit) && !$this->limit >= 0) { |
|
289 | 289 | $this->limit = self::DEFAULT_LIMIT; // This is a arbitrary number! |
290 | - trigger_error('Limit was not specifically set, so Tick defaulted to ' . self::DEFAULT_LIMIT, E_USER_NOTICE); |
|
290 | + trigger_error('Limit was not specifically set, so Tick defaulted to '.self::DEFAULT_LIMIT, E_USER_NOTICE); |
|
291 | 291 | } |
292 | 292 | return $this; |
293 | 293 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @return Objetc |
311 | 311 | * @see Iterator::current() |
312 | 312 | */ |
313 | - public function current(): object|null |
|
313 | + public function current(): object | null |
|
314 | 314 | { |
315 | 315 | return $this->getModel($this->position); |
316 | 316 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | public function next(): void |
337 | 337 | { |
338 | 338 | $this->getResult(); |
339 | - ++$this->position; |
|
339 | + ++ $this->position; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * |
360 | 360 | * @return Object |
361 | 361 | */ |
362 | - private function getModel(int $position): object|null |
|
362 | + private function getModel(int $position): object | null |
|
363 | 363 | { |
364 | 364 | $this->getResult(); |
365 | 365 | $class = get_class($this->model); |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $meta = $this->model->getMetadata(); |
368 | 368 | $fields = $meta["fields"]; |
369 | 369 | |
370 | - if (! $this->isEmpty()) { |
|
370 | + if (!$this->isEmpty()) { |
|
371 | 371 | foreach ($this->result[$position] as $field => $value) { |
372 | 372 | $property = $fields[$field]["property"]; |
373 | 373 | $propertyType = $fields[$field]["type"]; |