@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | use Alcaeus\MongoDbAdapter\TypeConverter; |
| 17 | 17 | |
| 18 | -if (! function_exists('bson_decode')) { |
|
| 18 | +if ( ! function_exists('bson_decode')) { |
|
| 19 | 19 | /** |
| 20 | 20 | * Deserializes a BSON object into a PHP array |
| 21 | 21 | * |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | -if (! function_exists('bson_encode')) { |
|
| 31 | +if ( ! function_exists('bson_encode')) { |
|
| 32 | 32 | /** |
| 33 | 33 | * Serializes a PHP variable into a BSON string |
| 34 | 34 | * |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public function add($item) |
| 77 | 77 | { |
| 78 | 78 | if (is_object($item)) { |
| 79 | - $item = (array)$item; |
|
| 79 | + $item = (array) $item; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $this->validate($item); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | final public function execute(array $writeOptions = []) |
| 96 | 96 | { |
| 97 | 97 | $writeOptions += $this->writeOptions; |
| 98 | - if (! count($this->items)) { |
|
| 98 | + if ( ! count($this->items)) { |
|
| 99 | 99 | return ['ok' => true]; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -152,19 +152,19 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | switch ($this->batchType) { |
| 154 | 154 | case self::COMMAND_UPDATE: |
| 155 | - if (! isset($item['q'])) { |
|
| 155 | + if ( ! isset($item['q'])) { |
|
| 156 | 156 | throw new Exception("Expected $item to contain 'q' key"); |
| 157 | 157 | } |
| 158 | - if (! isset($item['u'])) { |
|
| 158 | + if ( ! isset($item['u'])) { |
|
| 159 | 159 | throw new Exception("Expected $item to contain 'u' key"); |
| 160 | 160 | } |
| 161 | 161 | break; |
| 162 | 162 | |
| 163 | 163 | case self::COMMAND_DELETE: |
| 164 | - if (! isset($item['q'])) { |
|
| 164 | + if ( ! isset($item['q'])) { |
|
| 165 | 165 | throw new Exception("Expected $item to contain 'q' key"); |
| 166 | 166 | } |
| 167 | - if (! isset($item['limit'])) { |
|
| 167 | + if ( ! isset($item['limit'])) { |
|
| 168 | 168 | throw new Exception("Expected $item to contain 'limit' key"); |
| 169 | 169 | } |
| 170 | 170 | break; |
@@ -153,19 +153,19 @@ |
||
| 153 | 153 | switch ($this->batchType) { |
| 154 | 154 | case self::COMMAND_UPDATE: |
| 155 | 155 | if (! isset($item['q'])) { |
| 156 | - throw new Exception("Expected $item to contain 'q' key"); |
|
| 156 | + throw new Exception("expected $item to contain 'q' key"); |
|
| 157 | 157 | } |
| 158 | 158 | if (! isset($item['u'])) { |
| 159 | - throw new Exception("Expected $item to contain 'u' key"); |
|
| 159 | + throw new Exception("expected $item to contain 'u' key"); |
|
| 160 | 160 | } |
| 161 | 161 | break; |
| 162 | 162 | |
| 163 | 163 | case self::COMMAND_DELETE: |
| 164 | 164 | if (! isset($item['q'])) { |
| 165 | - throw new Exception("Expected $item to contain 'q' key"); |
|
| 165 | + throw new Exception("expected $item to contain 'q' key"); |
|
| 166 | 166 | } |
| 167 | 167 | if (! isset($item['limit'])) { |
| 168 | - throw new Exception("Expected $item to contain 'limit' key"); |
|
| 168 | + throw new Exception("expected $item to contain 'limit' key"); |
|
| 169 | 169 | } |
| 170 | 170 | break; |
| 171 | 171 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @link http://www.php.net/manual/en/mongocollection.aggregate.php |
| 124 | 124 | * @param array $pipeline |
| 125 | 125 | * @param array $op |
| 126 | - * @return array |
|
| 126 | + * @return null|Traversable |
|
| 127 | 127 | */ |
| 128 | 128 | public function aggregate(array $pipeline, array $op = []) |
| 129 | 129 | { |
@@ -923,6 +923,9 @@ discard block |
||
| 923 | 923 | return null; |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | + /** |
|
| 927 | + * @param string $name |
|
| 928 | + */ |
|
| 926 | 929 | private function checkCollectionName($name) |
| 927 | 930 | { |
| 928 | 931 | if (empty($name)) { |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function aggregate(array $pipeline, array $op = []) |
| 129 | 129 | { |
| 130 | - if (! TypeConverter::isNumericArray($pipeline)) { |
|
| 130 | + if ( ! TypeConverter::isNumericArray($pipeline)) { |
|
| 131 | 131 | $pipeline = []; |
| 132 | 132 | $options = []; |
| 133 | 133 | |
| 134 | 134 | $i = 0; |
| 135 | 135 | foreach (func_get_args() as $operator) { |
| 136 | 136 | $i++; |
| 137 | - if (! is_array($operator)) { |
|
| 137 | + if ( ! is_array($operator)) { |
|
| 138 | 138 | trigger_error("Argument $i is not an array", E_WARNING); |
| 139 | 139 | return; |
| 140 | 140 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | ]; |
| 182 | 182 | |
| 183 | 183 | // Convert cursor option |
| 184 | - if (! isset($options['cursor'])) { |
|
| 184 | + if ( ! isset($options['cursor'])) { |
|
| 185 | 185 | $options['cursor'] = true; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | public function insert(&$a, array $options = []) |
| 269 | 269 | { |
| 270 | - if (! $this->ensureDocumentHasMongoId($a)) { |
|
| 270 | + if ( ! $this->ensureDocumentHasMongoId($a)) { |
|
| 271 | 271 | trigger_error(sprintf('%s(): expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING); |
| 272 | 272 | return; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if (! count((array)$a)) { |
|
| 275 | + if ( ! count((array) $a)) { |
|
| 276 | 276 | throw new \MongoException('document must be an array or object'); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | throw ExceptionConverter::toLegacy($e); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - if (! $result->isAcknowledged()) { |
|
| 288 | + if ( ! $result->isAcknowledged()) { |
|
| 289 | 289 | return true; |
| 290 | 290 | } |
| 291 | 291 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | foreach ($a as $key => $item) { |
| 318 | 318 | try { |
| 319 | - if (! $this->ensureDocumentHasMongoId($a[$key])) { |
|
| 319 | + if ( ! $this->ensureDocumentHasMongoId($a[$key])) { |
|
| 320 | 320 | if ($continueOnError) { |
| 321 | 321 | unset($a[$key]); |
| 322 | 322 | } else { |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | throw ExceptionConverter::toLegacy($e); |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if (! $result->isAcknowledged()) { |
|
| 343 | + if ( ! $result->isAcknowledged()) { |
|
| 344 | 344 | return true; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @throws MongoCursorException |
| 365 | 365 | * @return boolean |
| 366 | 366 | */ |
| 367 | - public function update(array $criteria , array $newobj, array $options = []) |
|
| 367 | + public function update(array $criteria, array $newobj, array $options = []) |
|
| 368 | 368 | { |
| 369 | 369 | $multiple = isset($options['multiple']) ? $options['multiple'] : false; |
| 370 | 370 | $method = $multiple ? 'updateMany' : 'updateOne'; |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | throw ExceptionConverter::toLegacy($e); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if (! $result->isAcknowledged()) { |
|
| 384 | + if ( ! $result->isAcknowledged()) { |
|
| 385 | 385 | return true; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | public function remove(array $criteria = [], array $options = []) |
| 410 | 410 | { |
| 411 | - $multiple = isset($options['justOne']) ? !$options['justOne'] : true; |
|
| 411 | + $multiple = isset($options['justOne']) ? ! $options['justOne'] : true; |
|
| 412 | 412 | $method = $multiple ? 'deleteMany' : 'deleteOne'; |
| 413 | 413 | |
| 414 | 414 | try { |
@@ -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 | |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | $keys = (array) $keys; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - if (! is_array($keys) || ! count($keys)) { |
|
| 559 | + if ( ! is_array($keys) || ! count($keys)) { |
|
| 560 | 560 | throw new MongoException('keys cannot be empty'); |
| 561 | 561 | } |
| 562 | 562 | |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | $indexOptions = array_intersect_key($options, $neededOptions); |
| 566 | 566 | $indexes = $this->collection->listIndexes(); |
| 567 | 567 | foreach ($indexes as $index) { |
| 568 | - if (! empty($options['name']) && $index->getName() === $options['name']) { |
|
| 568 | + if ( ! empty($options['name']) && $index->getName() === $options['name']) { |
|
| 569 | 569 | throw new \MongoResultException(sprintf('index with name: %s already exists', $index->getName())); |
| 570 | 570 | } |
| 571 | 571 | |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | $this->convertWriteConcernOptions($options) |
| 714 | 714 | ); |
| 715 | 715 | |
| 716 | - if (! $result->isAcknowledged()) { |
|
| 716 | + if ( ! $result->isAcknowledged()) { |
|
| 717 | 717 | return true; |
| 718 | 718 | } |
| 719 | 719 | |
@@ -747,13 +747,13 @@ discard block |
||
| 747 | 747 | if ($document_or_id instanceof \MongoId) { |
| 748 | 748 | $id = $document_or_id; |
| 749 | 749 | } elseif (is_object($document_or_id)) { |
| 750 | - if (! isset($document_or_id->_id)) { |
|
| 750 | + if ( ! isset($document_or_id->_id)) { |
|
| 751 | 751 | return null; |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | $id = $document_or_id->_id; |
| 755 | 755 | } elseif (is_array($document_or_id)) { |
| 756 | - if (! isset($document_or_id['_id'])) { |
|
| 756 | + if ( ! isset($document_or_id['_id'])) { |
|
| 757 | 757 | return null; |
| 758 | 758 | } |
| 759 | 759 | |
@@ -796,14 +796,14 @@ discard block |
||
| 796 | 796 | $command = [ |
| 797 | 797 | 'group' => [ |
| 798 | 798 | 'ns' => $this->name, |
| 799 | - '$reduce' => (string)$reduce, |
|
| 799 | + '$reduce' => (string) $reduce, |
|
| 800 | 800 | 'initial' => $initial, |
| 801 | 801 | 'cond' => $condition, |
| 802 | 802 | ], |
| 803 | 803 | ]; |
| 804 | 804 | |
| 805 | 805 | if ($keys instanceof MongoCode) { |
| 806 | - $command['group']['$keyf'] = (string)$keys; |
|
| 806 | + $command['group']['$keyf'] = (string) $keys; |
|
| 807 | 807 | } else { |
| 808 | 808 | $command['group']['key'] = $keys; |
| 809 | 809 | } |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | } |
| 813 | 813 | if (array_key_exists('finalize', $condition)) { |
| 814 | 814 | if ($condition['finalize'] instanceof MongoCode) { |
| 815 | - $condition['finalize'] = (string)$condition['finalize']; |
|
| 815 | + $condition['finalize'] = (string) $condition['finalize']; |
|
| 816 | 816 | } |
| 817 | 817 | $command['group']['finalize'] = $condition['finalize']; |
| 818 | 818 | } |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | $options['w'] = ($options['safe']) ? 1 : 0; |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | - if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) { |
|
| 869 | + if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) { |
|
| 870 | 870 | $options['wTimeoutMS'] = $options['wtimeout']; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - if (isset($options['w']) || !isset($options['wTimeoutMS'])) { |
|
| 873 | + if (isset($options['w']) || ! isset($options['wTimeoutMS'])) { |
|
| 874 | 874 | $collectionWriteConcern = $this->getWriteConcern(); |
| 875 | 875 | $writeConcern = $this->createWriteConcernFromParameters( |
| 876 | 876 | isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'], |
@@ -903,7 +903,7 @@ discard block |
||
| 903 | 903 | }; |
| 904 | 904 | |
| 905 | 905 | if (is_array($document)) { |
| 906 | - if (! isset($document['_id'])) { |
|
| 906 | + if ( ! isset($document['_id'])) { |
|
| 907 | 907 | $document['_id'] = new \MongoId(); |
| 908 | 908 | } |
| 909 | 909 | |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | |
| 912 | 912 | return $document['_id']; |
| 913 | 913 | } elseif (is_object($document)) { |
| 914 | - if (! isset($document->_id)) { |
|
| 914 | + if ( ! isset($document->_id)) { |
|
| 915 | 915 | $document->_id = new \MongoId(); |
| 916 | 916 | } |
| 917 | 917 | |