@@ -11,6 +11,9 @@ |
||
11 | 11 | return $redis; |
12 | 12 | } |
13 | 13 | |
14 | + /** |
|
15 | + * @param Closure $fnc |
|
16 | + */ |
|
14 | 17 | public function eavesdrop($opts = ['criteria' => 0, 'options' => 1], $fnc, $args = []) |
15 | 18 | { |
16 | 19 | if (isset($opts['readArgs']) && !$opts['readArgs']) { |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | public function analyticalStore() |
6 | 6 | { |
7 | 7 | static $redis; |
8 | - if (!$redis) { |
|
8 | + if ( ! $redis) { |
|
9 | 9 | $redis = new Predis\Client(); |
10 | 10 | } |
11 | 11 | return $redis; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | public function eavesdrop($opts = ['criteria' => 0, 'options' => 1], $fnc, $args = []) |
15 | 15 | { |
16 | - if (isset($opts['readArgs']) && !$opts['readArgs']) { |
|
16 | + if (isset($opts['readArgs']) && ! $opts['readArgs']) { |
|
17 | 17 | $criteria = $opts['criteria'] ?? []; |
18 | 18 | $options = $opts['options'] ?? []; |
19 | 19 | $op = $opts['operation'] ?: null; |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | } else { |
22 | 22 | $criteria = isset($opts['criteria']) ? $args[$opts['criteria']] ?? [] : []; |
23 | 23 | $options = isset($opts['options']) ? ($args[$opts['options']] ?? []) : []; |
24 | - $op = is_array($fnc) && !isset($opts['operation']) ? |
|
24 | + $op = is_array($fnc) && ! isset($opts['operation']) ? |
|
25 | 25 | ($fnc[1] ?? null) : (isset($opts['operation']) ? ($opts['operation'] ?? null) : null); |
26 | 26 | $name = $opts['name'] ?? $this->name; |
27 | 27 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | private function analyticalNormalization(&$criteria) |
33 | 33 | { |
34 | 34 | if (is_array($criteria)) { |
35 | - array_walk($criteria, function (&$ref) { |
|
35 | + array_walk($criteria, function(&$ref) { |
|
36 | 36 | if (is_array($ref)) { |
37 | 37 | $this->analyticalNormalization($ref); |
38 | 38 | return; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $serialized = json_encode($payload); |
54 | 54 | $redisKey = sprintf("mongodb/%s/%s/%s", $name ?: $this->name, $op, md5($serialized)); |
55 | 55 | |
56 | - $onEnd = function () use ($serialized, $redisKey, $init) { |
|
56 | + $onEnd = function() use ($serialized, $redisKey, $init) { |
|
57 | 57 | $diff = ceil((microtime(true) - $init) * 1000); |
58 | 58 | if ($diff < 10) return; |
59 | 59 |
@@ -55,7 +55,9 @@ |
||
55 | 55 | |
56 | 56 | $onEnd = function () use ($serialized, $redisKey, $init) { |
57 | 57 | $diff = ceil((microtime(true) - $init) * 1000); |
58 | - if ($diff < 10) return; |
|
58 | + if ($diff < 10) { |
|
59 | + return; |
|
60 | + } |
|
59 | 61 | |
60 | 62 | $time = strtotime("+1 hour 00:00"); |
61 | 63 | $redis = $this->analyticalStore(); |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
493 | - * @return Cursor |
|
493 | + * @return Traversable |
|
494 | 494 | */ |
495 | 495 | protected function ensureCursor() |
496 | 496 | { |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | - * @return array |
|
537 | + * @return string[] |
|
538 | 538 | */ |
539 | 539 | public function __sleep() |
540 | 540 | { |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | 'options' => array_merge(['foundOnly'=> $foundOnly], $this->options), |
144 | 144 | 'operation' => 'count', |
145 | 145 | 'name' => $this->collection->getCollectionName() |
146 | - ], function () use ($foundOnly) { |
|
146 | + ], function() use ($foundOnly) { |
|
147 | 147 | $optionNames = ['hint', 'maxTimeMS']; |
148 | 148 | if ($foundOnly) { |
149 | 149 | $optionNames = array_merge($optionNames, ['limit', 'skip']); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | 'options' => $this->options, |
174 | 174 | 'operation' => 'count', |
175 | 175 | 'name' => $this->collection->getCollectionName() |
176 | - ], function () { |
|
176 | + ], function() { |
|
177 | 177 | // MongoDB\Driver\Cursor needs to be wrapped into a \Generator so that a valid \Iterator with working implementations of |
178 | 178 | // next, current, valid, key and rewind is returned. These methods don't work if we wrap the Cursor inside an \IteratorIterator |
179 | 179 | if ($this->iterator === null) { |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function hasNext() |
273 | 273 | { |
274 | - if (! $this->startedIterating) { |
|
274 | + if ( ! $this->startedIterating) { |
|
275 | 275 | $this->ensureIterator(); |
276 | 276 | $this->startedIterating = true; |
277 | 277 | $this->storeIteratorState(); |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | */ |
457 | 457 | protected function convertCursorType() |
458 | 458 | { |
459 | - if (! $this->tailable) { |
|
459 | + if ( ! $this->tailable) { |
|
460 | 460 | return null; |
461 | 461 | } |
462 | 462 | |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | protected function wrapTraversable(\Traversable $traversable) |
511 | 511 | { |
512 | 512 | foreach ($traversable as $key => $value) { |
513 | - if (isset($value->_id) && ($value->_id instanceof \MongoDB\BSON\ObjectID || !is_object($value->_id))) { |
|
513 | + if (isset($value->_id) && ($value->_id instanceof \MongoDB\BSON\ObjectID || ! is_object($value->_id))) { |
|
514 | 514 | $key = (string) $value->_id; |
515 | 515 | } |
516 | 516 | yield $key => $value; |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | 'criteria' => 0, |
143 | 143 | 'options' => 1, |
144 | 144 | 'operation' => 'aggregate' |
145 | - ], function () use ($pipeline, $op) { |
|
146 | - if (! TypeConverter::isNumericArray($pipeline)) { |
|
145 | + ], function() use ($pipeline, $op) { |
|
146 | + if ( ! TypeConverter::isNumericArray($pipeline)) { |
|
147 | 147 | $operators = func_get_args(); |
148 | 148 | $pipeline = []; |
149 | 149 | $options = []; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $i = 0; |
152 | 152 | foreach ($operators as $operator) { |
153 | 153 | $i++; |
154 | - if (! is_array($operator)) { |
|
154 | + if ( ! is_array($operator)) { |
|
155 | 155 | trigger_error("Argument $i is not an array", E_USER_WARNING); |
156 | 156 | return; |
157 | 157 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | ]; |
206 | 206 | |
207 | 207 | // Convert cursor option |
208 | - if (! isset($options['cursor'])) { |
|
208 | + if ( ! isset($options['cursor'])) { |
|
209 | 209 | $options['cursor'] = new \stdClass(); |
210 | 210 | } |
211 | 211 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function insert(&$a, array $options = []) |
293 | 293 | { |
294 | - if (! $this->ensureDocumentHasMongoId($a)) { |
|
294 | + if ( ! $this->ensureDocumentHasMongoId($a)) { |
|
295 | 295 | trigger_error(sprintf('%s(): expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING); |
296 | 296 | return; |
297 | 297 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | throw ExceptionConverter::toLegacy($e); |
308 | 308 | } |
309 | 309 | |
310 | - if (! $result->isAcknowledged()) { |
|
310 | + if ( ! $result->isAcknowledged()) { |
|
311 | 311 | return true; |
312 | 312 | } |
313 | 313 | |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | |
339 | 339 | foreach ($a as $key => $item) { |
340 | 340 | try { |
341 | - if (! $this->ensureDocumentHasMongoId($a[$key])) { |
|
341 | + if ( ! $this->ensureDocumentHasMongoId($a[$key])) { |
|
342 | 342 | if ($continueOnError) { |
343 | 343 | unset($a[$key]); |
344 | 344 | } else { |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | } |
348 | 348 | } |
349 | 349 | } catch (MongoException $e) { |
350 | - if (! $continueOnError) { |
|
350 | + if ( ! $continueOnError) { |
|
351 | 351 | throw $e; |
352 | 352 | } |
353 | 353 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | throw ExceptionConverter::toLegacy($e, 'MongoResultException'); |
363 | 363 | } |
364 | 364 | |
365 | - if (! $result->isAcknowledged()) { |
|
365 | + if ( ! $result->isAcknowledged()) { |
|
366 | 366 | return true; |
367 | 367 | } |
368 | 368 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | 'criteria' => 0, |
394 | 394 | 'options' => 2, |
395 | 395 | 'operation' => 'update' |
396 | - ], function () use ($criteria, $newobj, $options) { |
|
396 | + ], function() use ($criteria, $newobj, $options) { |
|
397 | 397 | $this->mustBeArrayOrObject($criteria); |
398 | 398 | $this->mustBeArrayOrObject($newobj); |
399 | 399 | |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | throw ExceptionConverter::toLegacy($e); |
422 | 422 | } |
423 | 423 | |
424 | - if (! $result->isAcknowledged()) { |
|
424 | + if ( ! $result->isAcknowledged()) { |
|
425 | 425 | return true; |
426 | 426 | } |
427 | 427 | |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | 'criteria' => 0, |
454 | 454 | 'options' => 1, |
455 | 455 | 'operation' => 'remove' |
456 | - ], function () use ($criteria, $options) { |
|
457 | - $multiple = isset($options['justOne']) ? !$options['justOne'] : true; |
|
456 | + ], function() use ($criteria, $options) { |
|
457 | + $multiple = isset($options['justOne']) ? ! $options['justOne'] : true; |
|
458 | 458 | $method = $multiple ? 'deleteMany' : 'deleteOne'; |
459 | 459 | |
460 | 460 | try { |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | throw ExceptionConverter::toLegacy($e); |
468 | 468 | } |
469 | 469 | |
470 | - if (! $result->isAcknowledged()) { |
|
470 | + if ( ! $result->isAcknowledged()) { |
|
471 | 471 | return true; |
472 | 472 | } |
473 | 473 | |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | 'criteria' => 1, |
511 | 511 | 'options' => 0, |
512 | 512 | 'operation' => 'distinct' |
513 | - ], function () use ($key, $query) { |
|
513 | + ], function() use ($key, $query) { |
|
514 | 514 | try { |
515 | 515 | return array_map([TypeConverter::class, 'toLegacy'], $this->collection->distinct($key, TypeConverter::fromLegacy($query))); |
516 | 516 | } catch (\MongoDB\Driver\Exception\Exception $e) { |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | 'criteria' => 0, |
536 | 536 | 'options' => 3, |
537 | 537 | 'operation' => 'findAndModify' |
538 | - ], function () use ($query, $update, $fields, $options) { |
|
538 | + ], function() use ($query, $update, $fields, $options) { |
|
539 | 539 | $query = TypeConverter::fromLegacy($query); |
540 | 540 | try { |
541 | 541 | if (isset($options['remove'])) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | $options['projection'] = TypeConverter::convertProjection($fields); |
559 | 559 | |
560 | - if (! \MongoDB\is_first_key_operator($update)) { |
|
560 | + if ( ! \MongoDB\is_first_key_operator($update)) { |
|
561 | 561 | $document = $this->collection->findOneAndReplace($query, $update, $options); |
562 | 562 | } else { |
563 | 563 | $document = $this->collection->findOneAndUpdate($query, $update, $options); |
@@ -592,9 +592,9 @@ discard block |
||
592 | 592 | 'criteria' => 0, |
593 | 593 | 'options' => 2, |
594 | 594 | 'operation' => 'findOne' |
595 | - ], function () use ($query, $fields, $options) { |
|
595 | + ], function() use ($query, $fields, $options) { |
|
596 | 596 | // Can't typehint for array since MongoGridFS extends and accepts strings |
597 | - if (! is_array($query)) { |
|
597 | + if ( ! is_array($query)) { |
|
598 | 598 | trigger_error(sprintf('MongoCollection::findOne(): expects parameter 1 to be an array or object, %s given', gettype($query)), E_USER_WARNING); |
599 | 599 | return; |
600 | 600 | } |
@@ -635,11 +635,11 @@ discard block |
||
635 | 635 | $keys = (array) $keys; |
636 | 636 | } |
637 | 637 | |
638 | - if (! is_array($keys) || ! count($keys)) { |
|
638 | + if ( ! is_array($keys) || ! count($keys)) { |
|
639 | 639 | throw new MongoException('index specification has no elements'); |
640 | 640 | } |
641 | 641 | |
642 | - if (! isset($options['name'])) { |
|
642 | + if ( ! isset($options['name'])) { |
|
643 | 643 | $options['name'] = \MongoDB\generate_index_name($keys); |
644 | 644 | } |
645 | 645 | |
@@ -674,14 +674,14 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | $result = [ |
677 | - 'createdCollectionAutomatically' => !$collectionExists, |
|
677 | + 'createdCollectionAutomatically' => ! $collectionExists, |
|
678 | 678 | 'numIndexesBefore' => $indexCount, |
679 | 679 | 'numIndexesAfter' => $indexCount, |
680 | 680 | 'note' => 'all indexes already exist', |
681 | 681 | 'ok' => 1.0, |
682 | 682 | ]; |
683 | 683 | |
684 | - if (! $indexExists) { |
|
684 | + if ( ! $indexExists) { |
|
685 | 685 | $result['numIndexesAfter']++; |
686 | 686 | unset($result['note']); |
687 | 687 | } |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | { |
715 | 715 | if (is_string($keys)) { |
716 | 716 | $indexName = $keys; |
717 | - if (! preg_match('#_-?1$#', $indexName)) { |
|
717 | + if ( ! preg_match('#_-?1$#', $indexName)) { |
|
718 | 718 | $indexName .= '_1'; |
719 | 719 | } |
720 | 720 | } elseif (is_array($keys)) { |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | */ |
754 | 754 | public function getIndexInfo() |
755 | 755 | { |
756 | - $convertIndex = function (\MongoDB\Model\IndexInfo $indexInfo) { |
|
756 | + $convertIndex = function(\MongoDB\Model\IndexInfo $indexInfo) { |
|
757 | 757 | $infos = [ |
758 | 758 | 'v' => $indexInfo->getVersion(), |
759 | 759 | 'key' => $indexInfo->getKey(), |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | ]; |
778 | 778 | |
779 | 779 | foreach ($additionalKeys as $key) { |
780 | - if (! isset($indexInfo[$key])) { |
|
780 | + if ( ! isset($indexInfo[$key])) { |
|
781 | 781 | continue; |
782 | 782 | } |
783 | 783 | |
@@ -804,10 +804,10 @@ discard block |
||
804 | 804 | 'criteria' => 0, |
805 | 805 | 'options' => 1, |
806 | 806 | 'operation' => 'count' |
807 | - ], function () use ($query, $options) { |
|
807 | + ], function() use ($query, $options) { |
|
808 | 808 | try { |
809 | 809 | // Handle legacy mode - limit and skip as second and third parameters, respectively |
810 | - if (! is_array($options)) { |
|
810 | + if ( ! is_array($options)) { |
|
811 | 811 | $limit = $options; |
812 | 812 | $options = []; |
813 | 813 | |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | $this->convertWriteConcernOptions($options) |
856 | 856 | ); |
857 | 857 | |
858 | - if (! $result->isAcknowledged()) { |
|
858 | + if ( ! $result->isAcknowledged()) { |
|
859 | 859 | return true; |
860 | 860 | } |
861 | 861 | |
@@ -889,13 +889,13 @@ discard block |
||
889 | 889 | if ($document_or_id instanceof \MongoId) { |
890 | 890 | $id = $document_or_id; |
891 | 891 | } elseif (is_object($document_or_id)) { |
892 | - if (! isset($document_or_id->_id)) { |
|
892 | + if ( ! isset($document_or_id->_id)) { |
|
893 | 893 | return null; |
894 | 894 | } |
895 | 895 | |
896 | 896 | $id = $document_or_id->_id; |
897 | 897 | } elseif (is_array($document_or_id)) { |
898 | - if (! isset($document_or_id['_id'])) { |
|
898 | + if ( ! isset($document_or_id['_id'])) { |
|
899 | 899 | return null; |
900 | 900 | } |
901 | 901 | |
@@ -1008,11 +1008,11 @@ discard block |
||
1008 | 1008 | $options['w'] = ($options['safe']) ? 1 : 0; |
1009 | 1009 | } |
1010 | 1010 | |
1011 | - if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) { |
|
1011 | + if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) { |
|
1012 | 1012 | $options['wTimeoutMS'] = $options['wtimeout']; |
1013 | 1013 | } |
1014 | 1014 | |
1015 | - if (isset($options['w']) || !isset($options['wTimeoutMS'])) { |
|
1015 | + if (isset($options['w']) || ! isset($options['wTimeoutMS'])) { |
|
1016 | 1016 | $collectionWriteConcern = $this->getWriteConcern(); |
1017 | 1017 | $writeConcern = $this->createWriteConcernFromParameters( |
1018 | 1018 | isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'], |
@@ -1050,7 +1050,7 @@ discard block |
||
1050 | 1050 | private function ensureDocumentHasMongoId(&$document) |
1051 | 1051 | { |
1052 | 1052 | if (is_array($document)) { |
1053 | - if (! isset($document['_id'])) { |
|
1053 | + if ( ! isset($document['_id'])) { |
|
1054 | 1054 | $document['_id'] = new \MongoId(); |
1055 | 1055 | } |
1056 | 1056 | |
@@ -1060,12 +1060,12 @@ discard block |
||
1060 | 1060 | } elseif (is_object($document)) { |
1061 | 1061 | $reflectionObject = new \ReflectionObject($document); |
1062 | 1062 | foreach ($reflectionObject->getProperties() as $property) { |
1063 | - if (! $property->isPublic()) { |
|
1063 | + if ( ! $property->isPublic()) { |
|
1064 | 1064 | throw new \MongoException('zero-length keys are not allowed, did you use $ with double quotes?'); |
1065 | 1065 | } |
1066 | 1066 | } |
1067 | 1067 | |
1068 | - if (! isset($document->_id)) { |
|
1068 | + if ( ! isset($document->_id)) { |
|
1069 | 1069 | $document->_id = new \MongoId(); |
1070 | 1070 | } |
1071 | 1071 | |
@@ -1096,7 +1096,7 @@ discard block |
||
1096 | 1096 | |
1097 | 1097 | private function mustBeArrayOrObject($a) |
1098 | 1098 | { |
1099 | - if (!is_array($a) && !is_object($a)) { |
|
1099 | + if ( ! is_array($a) && ! is_object($a)) { |
|
1100 | 1100 | throw new \MongoException('document must be an array or object'); |
1101 | 1101 | } |
1102 | 1102 | } |
@@ -152,7 +152,7 @@ |
||
152 | 152 | foreach ($operators as $operator) { |
153 | 153 | $i++; |
154 | 154 | if (! is_array($operator)) { |
155 | - trigger_error("Argument $i is not an array", E_USER_WARNING); |
|
155 | + trigger_error("argument $i is not an array", E_USER_WARNING); |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 |