@@ -511,6 +511,9 @@ discard block |
||
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | + /** |
|
515 | + * @param string $name |
|
516 | + */ |
|
514 | 517 | private function checkDatabaseName($name) |
515 | 518 | { |
516 | 519 | if (empty($name)) { |
@@ -543,7 +546,7 @@ discard block |
||
543 | 546 | } |
544 | 547 | |
545 | 548 | /** |
546 | - * @return array |
|
549 | + * @return string[] |
|
547 | 550 | */ |
548 | 551 | public function __sleep() |
549 | 552 | { |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function aggregate(array $pipeline, array $op = []) |
132 | 132 | { |
133 | - if (! TypeConverter::isNumericArray($pipeline)) { |
|
133 | + if ( ! TypeConverter::isNumericArray($pipeline)) { |
|
134 | 134 | $pipeline = []; |
135 | 135 | $options = []; |
136 | 136 | |
137 | 137 | $i = 0; |
138 | 138 | foreach (func_get_args() as $operator) { |
139 | 139 | $i++; |
140 | - if (! is_array($operator)) { |
|
140 | + if ( ! is_array($operator)) { |
|
141 | 141 | trigger_error("Argument $i is not an array", E_WARNING); |
142 | 142 | return; |
143 | 143 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | 'waitedMS' => 0, |
170 | 170 | ]; |
171 | 171 | } catch (\MongoDB\Driver\Exception\Exception $e) { |
172 | - throw ExceptionConverter::toLegacy($e,'MongoResultException'); |
|
172 | + throw ExceptionConverter::toLegacy($e, 'MongoResultException'); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | ]; |
191 | 191 | |
192 | 192 | // Convert cursor option |
193 | - if (! isset($options['cursor'])) { |
|
193 | + if ( ! isset($options['cursor'])) { |
|
194 | 194 | $options['cursor'] = new \stdClass(); |
195 | 195 | } |
196 | 196 | |
@@ -276,12 +276,12 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function insert(&$a, array $options = []) |
278 | 278 | { |
279 | - if (! $this->ensureDocumentHasMongoId($a)) { |
|
279 | + if ( ! $this->ensureDocumentHasMongoId($a)) { |
|
280 | 280 | trigger_error(sprintf('%s(): expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING); |
281 | 281 | return; |
282 | 282 | } |
283 | 283 | |
284 | - if (! count((array)$a)) { |
|
284 | + if ( ! count((array) $a)) { |
|
285 | 285 | throw new \MongoException('document must be an array or object'); |
286 | 286 | } |
287 | 287 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | throw ExceptionConverter::toLegacy($e); |
295 | 295 | } |
296 | 296 | |
297 | - if (! $result->isAcknowledged()) { |
|
297 | + if ( ! $result->isAcknowledged()) { |
|
298 | 298 | return true; |
299 | 299 | } |
300 | 300 | |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | |
326 | 326 | foreach ($a as $key => $item) { |
327 | 327 | try { |
328 | - if (! $this->ensureDocumentHasMongoId($a[$key])) { |
|
328 | + if ( ! $this->ensureDocumentHasMongoId($a[$key])) { |
|
329 | 329 | if ($continueOnError) { |
330 | 330 | unset($a[$key]); |
331 | 331 | } else { |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | throw ExceptionConverter::toLegacy($e, 'MongoResultException'); |
350 | 350 | } |
351 | 351 | |
352 | - if (! $result->isAcknowledged()) { |
|
352 | + if ( ! $result->isAcknowledged()) { |
|
353 | 353 | return true; |
354 | 354 | } |
355 | 355 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @throws MongoCursorException |
374 | 374 | * @return boolean |
375 | 375 | */ |
376 | - public function update(array $criteria , array $newobj, array $options = []) |
|
376 | + public function update(array $criteria, array $newobj, array $options = []) |
|
377 | 377 | { |
378 | 378 | $multiple = isset($options['multiple']) ? $options['multiple'] : false; |
379 | 379 | $isReplace = ! \MongoDB\is_first_key_operator($newobj); |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | throw ExceptionConverter::toLegacy($e); |
398 | 398 | } |
399 | 399 | |
400 | - if (! $result->isAcknowledged()) { |
|
400 | + if ( ! $result->isAcknowledged()) { |
|
401 | 401 | return true; |
402 | 402 | } |
403 | 403 | |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | */ |
425 | 425 | public function remove(array $criteria = [], array $options = []) |
426 | 426 | { |
427 | - $multiple = isset($options['justOne']) ? !$options['justOne'] : true; |
|
427 | + $multiple = isset($options['justOne']) ? ! $options['justOne'] : true; |
|
428 | 428 | $method = $multiple ? 'deleteMany' : 'deleteOne'; |
429 | 429 | |
430 | 430 | try { |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | throw ExceptionConverter::toLegacy($e); |
438 | 438 | } |
439 | 439 | |
440 | - if (! $result->isAcknowledged()) { |
|
440 | + if ( ! $result->isAcknowledged()) { |
|
441 | 441 | return true; |
442 | 442 | } |
443 | 443 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | |
510 | 510 | $options['projection'] = is_array($fields) ? TypeConverter::fromLegacy($fields) : []; |
511 | 511 | |
512 | - if (! \MongoDB\is_first_key_operator($update)) { |
|
512 | + if ( ! \MongoDB\is_first_key_operator($update)) { |
|
513 | 513 | $document = $this->collection->findOneAndReplace($query, $update, $options); |
514 | 514 | } else { |
515 | 515 | $document = $this->collection->findOneAndUpdate($query, $update, $options); |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | public function findOne($query = [], array $fields = [], array $options = []) |
541 | 541 | { |
542 | 542 | // Can't typehint for array since MongoGridFS extends and accepts strings |
543 | - if (! is_array($query)) { |
|
543 | + if ( ! is_array($query)) { |
|
544 | 544 | trigger_error(sprintf('MongoCollection::findOne(): expects parameter 1 to be an array or object, %s given', gettype($query)), E_WARNING); |
545 | 545 | return; |
546 | 546 | } |
@@ -580,11 +580,11 @@ discard block |
||
580 | 580 | $keys = (array) $keys; |
581 | 581 | } |
582 | 582 | |
583 | - if (! is_array($keys) || ! count($keys)) { |
|
583 | + if ( ! is_array($keys) || ! count($keys)) { |
|
584 | 584 | throw new MongoException('index specification has no elements'); |
585 | 585 | } |
586 | 586 | |
587 | - if (! isset($options['name'])) { |
|
587 | + if ( ! isset($options['name'])) { |
|
588 | 588 | $options['name'] = \MongoDB\generate_index_name($keys); |
589 | 589 | } |
590 | 590 | |
@@ -619,14 +619,14 @@ discard block |
||
619 | 619 | } |
620 | 620 | |
621 | 621 | $result = [ |
622 | - 'createdCollectionAutomatically' => !$collectionExists, |
|
622 | + 'createdCollectionAutomatically' => ! $collectionExists, |
|
623 | 623 | 'numIndexesBefore' => $indexCount, |
624 | 624 | 'numIndexesAfter' => $indexCount, |
625 | 625 | 'note' => 'all indexes already exist', |
626 | 626 | 'ok' => 1.0, |
627 | 627 | ]; |
628 | 628 | |
629 | - if (! $indexExists) { |
|
629 | + if ( ! $indexExists) { |
|
630 | 630 | $result['numIndexesAfter']++; |
631 | 631 | unset($result['note']); |
632 | 632 | } |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | { |
660 | 660 | if (is_string($keys)) { |
661 | 661 | $indexName = $keys; |
662 | - if (! preg_match('#_-?1$#', $indexName)) { |
|
662 | + if ( ! preg_match('#_-?1$#', $indexName)) { |
|
663 | 663 | $indexName .= '_1'; |
664 | 664 | } |
665 | 665 | } elseif (is_array($keys)) { |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | $this->convertWriteConcernOptions($options) |
756 | 756 | ); |
757 | 757 | |
758 | - if (! $result->isAcknowledged()) { |
|
758 | + if ( ! $result->isAcknowledged()) { |
|
759 | 759 | return true; |
760 | 760 | } |
761 | 761 | |
@@ -789,13 +789,13 @@ discard block |
||
789 | 789 | if ($document_or_id instanceof \MongoId) { |
790 | 790 | $id = $document_or_id; |
791 | 791 | } elseif (is_object($document_or_id)) { |
792 | - if (! isset($document_or_id->_id)) { |
|
792 | + if ( ! isset($document_or_id->_id)) { |
|
793 | 793 | return null; |
794 | 794 | } |
795 | 795 | |
796 | 796 | $id = $document_or_id->_id; |
797 | 797 | } elseif (is_array($document_or_id)) { |
798 | - if (! isset($document_or_id['_id'])) { |
|
798 | + if ( ! isset($document_or_id['_id'])) { |
|
799 | 799 | return null; |
800 | 800 | } |
801 | 801 | |
@@ -838,14 +838,14 @@ discard block |
||
838 | 838 | $command = [ |
839 | 839 | 'group' => [ |
840 | 840 | 'ns' => $this->name, |
841 | - '$reduce' => (string)$reduce, |
|
841 | + '$reduce' => (string) $reduce, |
|
842 | 842 | 'initial' => $initial, |
843 | 843 | 'cond' => $condition, |
844 | 844 | ], |
845 | 845 | ]; |
846 | 846 | |
847 | 847 | if ($keys instanceof MongoCode) { |
848 | - $command['group']['$keyf'] = (string)$keys; |
|
848 | + $command['group']['$keyf'] = (string) $keys; |
|
849 | 849 | } else { |
850 | 850 | $command['group']['key'] = $keys; |
851 | 851 | } |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | } |
855 | 855 | if (array_key_exists('finalize', $condition)) { |
856 | 856 | if ($condition['finalize'] instanceof MongoCode) { |
857 | - $condition['finalize'] = (string)$condition['finalize']; |
|
857 | + $condition['finalize'] = (string) $condition['finalize']; |
|
858 | 858 | } |
859 | 859 | $command['group']['finalize'] = $condition['finalize']; |
860 | 860 | } |
@@ -908,11 +908,11 @@ discard block |
||
908 | 908 | $options['w'] = ($options['safe']) ? 1 : 0; |
909 | 909 | } |
910 | 910 | |
911 | - if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) { |
|
911 | + if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) { |
|
912 | 912 | $options['wTimeoutMS'] = $options['wtimeout']; |
913 | 913 | } |
914 | 914 | |
915 | - if (isset($options['w']) || !isset($options['wTimeoutMS'])) { |
|
915 | + if (isset($options['w']) || ! isset($options['wTimeoutMS'])) { |
|
916 | 916 | $collectionWriteConcern = $this->getWriteConcern(); |
917 | 917 | $writeConcern = $this->createWriteConcernFromParameters( |
918 | 918 | isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'], |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | }; |
946 | 946 | |
947 | 947 | if (is_array($document)) { |
948 | - if (! isset($document['_id'])) { |
|
948 | + if ( ! isset($document['_id'])) { |
|
949 | 949 | $document['_id'] = new \MongoId(); |
950 | 950 | } |
951 | 951 | |
@@ -955,12 +955,12 @@ discard block |
||
955 | 955 | } elseif (is_object($document)) { |
956 | 956 | $reflectionObject = new \ReflectionObject($document); |
957 | 957 | foreach ($reflectionObject->getProperties() as $property) { |
958 | - if (! $property->isPublic()) { |
|
958 | + if ( ! $property->isPublic()) { |
|
959 | 959 | throw new \MongoException('zero-length keys are not allowed, did you use $ with double quotes?'); |
960 | 960 | } |
961 | 961 | } |
962 | 962 | |
963 | - if (! isset($document->_id)) { |
|
963 | + if ( ! isset($document->_id)) { |
|
964 | 964 | $document->_id = new \MongoId(); |
965 | 965 | } |
966 | 966 |