@@ -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)) { |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function aggregate(array $pipeline, array $op = []) |
| 128 | 128 | { |
| 129 | - if (! TypeConverter::isNumericArray($pipeline)) { |
|
| 129 | + if ( ! TypeConverter::isNumericArray($pipeline)) { |
|
| 130 | 130 | $pipeline = []; |
| 131 | 131 | $options = []; |
| 132 | 132 | |
| 133 | 133 | $i = 0; |
| 134 | 134 | foreach (func_get_args() as $operator) { |
| 135 | 135 | $i++; |
| 136 | - if (! is_array($operator)) { |
|
| 136 | + if ( ! is_array($operator)) { |
|
| 137 | 137 | trigger_error("Argument $i is not an array", E_WARNING); |
| 138 | 138 | return; |
| 139 | 139 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | ]; |
| 181 | 181 | |
| 182 | 182 | // Convert cursor option |
| 183 | - if (! isset($options['cursor'])) { |
|
| 183 | + if ( ! isset($options['cursor'])) { |
|
| 184 | 184 | $options['cursor'] = new \stdClass(); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -266,12 +266,12 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public function insert(&$a, array $options = []) |
| 268 | 268 | { |
| 269 | - if (! $this->ensureDocumentHasMongoId($a)) { |
|
| 269 | + if ( ! $this->ensureDocumentHasMongoId($a)) { |
|
| 270 | 270 | trigger_error(sprintf('%s(): expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING); |
| 271 | 271 | return; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if (! count((array)$a)) { |
|
| 274 | + if ( ! count((array) $a)) { |
|
| 275 | 275 | throw new \MongoException('document must be an array or object'); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | throw ExceptionConverter::toLegacy($e); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if (! $result->isAcknowledged()) { |
|
| 287 | + if ( ! $result->isAcknowledged()) { |
|
| 288 | 288 | return true; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | foreach ($a as $key => $item) { |
| 317 | 317 | try { |
| 318 | - if (! $this->ensureDocumentHasMongoId($a[$key])) { |
|
| 318 | + if ( ! $this->ensureDocumentHasMongoId($a[$key])) { |
|
| 319 | 319 | if ($continueOnError) { |
| 320 | 320 | unset($a[$key]); |
| 321 | 321 | } else { |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | throw ExceptionConverter::toLegacy($e); |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if (! $result->isAcknowledged()) { |
|
| 342 | + if ( ! $result->isAcknowledged()) { |
|
| 343 | 343 | return true; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * @throws MongoCursorException |
| 364 | 364 | * @return boolean |
| 365 | 365 | */ |
| 366 | - public function update(array $criteria , array $newobj, array $options = []) |
|
| 366 | + public function update(array $criteria, array $newobj, array $options = []) |
|
| 367 | 367 | { |
| 368 | 368 | $multiple = isset($options['multiple']) ? $options['multiple'] : false; |
| 369 | 369 | $method = $multiple ? 'updateMany' : 'updateOne'; |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | throw ExceptionConverter::toLegacy($e); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if (! $result->isAcknowledged()) { |
|
| 383 | + if ( ! $result->isAcknowledged()) { |
|
| 384 | 384 | return true; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | */ |
| 408 | 408 | public function remove(array $criteria = [], array $options = []) |
| 409 | 409 | { |
| 410 | - $multiple = isset($options['justOne']) ? !$options['justOne'] : true; |
|
| 410 | + $multiple = isset($options['justOne']) ? ! $options['justOne'] : true; |
|
| 411 | 411 | $method = $multiple ? 'deleteMany' : 'deleteOne'; |
| 412 | 412 | |
| 413 | 413 | try { |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | throw ExceptionConverter::toLegacy($e); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - if (! $result->isAcknowledged()) { |
|
| 423 | + if ( ! $result->isAcknowledged()) { |
|
| 424 | 424 | return true; |
| 425 | 425 | } |
| 426 | 426 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | |
| 493 | 493 | $options['projection'] = is_array($fields) ? TypeConverter::fromLegacy($fields) : []; |
| 494 | 494 | |
| 495 | - if (! \MongoDB\is_first_key_operator($update)) { |
|
| 495 | + if ( ! \MongoDB\is_first_key_operator($update)) { |
|
| 496 | 496 | $document = $this->collection->findOneAndReplace($query, $update, $options); |
| 497 | 497 | } else { |
| 498 | 498 | $document = $this->collection->findOneAndUpdate($query, $update, $options); |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | $keys = (array) $keys; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - if (! is_array($keys) || ! count($keys)) { |
|
| 562 | + if ( ! is_array($keys) || ! count($keys)) { |
|
| 563 | 563 | throw new MongoException('keys cannot be empty'); |
| 564 | 564 | } |
| 565 | 565 | |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | $indexOptions = array_intersect_key($options, $neededOptions); |
| 569 | 569 | $indexes = $this->collection->listIndexes(); |
| 570 | 570 | foreach ($indexes as $index) { |
| 571 | - if (! empty($options['name']) && $index->getName() === $options['name']) { |
|
| 571 | + if ( ! empty($options['name']) && $index->getName() === $options['name']) { |
|
| 572 | 572 | throw new \MongoResultException(sprintf('index with name: %s already exists', $index->getName())); |
| 573 | 573 | } |
| 574 | 574 | |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | $this->convertWriteConcernOptions($options) |
| 717 | 717 | ); |
| 718 | 718 | |
| 719 | - if (! $result->isAcknowledged()) { |
|
| 719 | + if ( ! $result->isAcknowledged()) { |
|
| 720 | 720 | return true; |
| 721 | 721 | } |
| 722 | 722 | |
@@ -750,13 +750,13 @@ discard block |
||
| 750 | 750 | if ($document_or_id instanceof \MongoId) { |
| 751 | 751 | $id = $document_or_id; |
| 752 | 752 | } elseif (is_object($document_or_id)) { |
| 753 | - if (! isset($document_or_id->_id)) { |
|
| 753 | + if ( ! isset($document_or_id->_id)) { |
|
| 754 | 754 | return null; |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | $id = $document_or_id->_id; |
| 758 | 758 | } elseif (is_array($document_or_id)) { |
| 759 | - if (! isset($document_or_id['_id'])) { |
|
| 759 | + if ( ! isset($document_or_id['_id'])) { |
|
| 760 | 760 | return null; |
| 761 | 761 | } |
| 762 | 762 | |
@@ -799,14 +799,14 @@ discard block |
||
| 799 | 799 | $command = [ |
| 800 | 800 | 'group' => [ |
| 801 | 801 | 'ns' => $this->name, |
| 802 | - '$reduce' => (string)$reduce, |
|
| 802 | + '$reduce' => (string) $reduce, |
|
| 803 | 803 | 'initial' => $initial, |
| 804 | 804 | 'cond' => $condition, |
| 805 | 805 | ], |
| 806 | 806 | ]; |
| 807 | 807 | |
| 808 | 808 | if ($keys instanceof MongoCode) { |
| 809 | - $command['group']['$keyf'] = (string)$keys; |
|
| 809 | + $command['group']['$keyf'] = (string) $keys; |
|
| 810 | 810 | } else { |
| 811 | 811 | $command['group']['key'] = $keys; |
| 812 | 812 | } |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | } |
| 816 | 816 | if (array_key_exists('finalize', $condition)) { |
| 817 | 817 | if ($condition['finalize'] instanceof MongoCode) { |
| 818 | - $condition['finalize'] = (string)$condition['finalize']; |
|
| 818 | + $condition['finalize'] = (string) $condition['finalize']; |
|
| 819 | 819 | } |
| 820 | 820 | $command['group']['finalize'] = $condition['finalize']; |
| 821 | 821 | } |
@@ -869,11 +869,11 @@ discard block |
||
| 869 | 869 | $options['w'] = ($options['safe']) ? 1 : 0; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) { |
|
| 872 | + if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) { |
|
| 873 | 873 | $options['wTimeoutMS'] = $options['wtimeout']; |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | - if (isset($options['w']) || !isset($options['wTimeoutMS'])) { |
|
| 876 | + if (isset($options['w']) || ! isset($options['wTimeoutMS'])) { |
|
| 877 | 877 | $collectionWriteConcern = $this->getWriteConcern(); |
| 878 | 878 | $writeConcern = $this->createWriteConcernFromParameters( |
| 879 | 879 | isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'], |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | }; |
| 907 | 907 | |
| 908 | 908 | if (is_array($document)) { |
| 909 | - if (! isset($document['_id'])) { |
|
| 909 | + if ( ! isset($document['_id'])) { |
|
| 910 | 910 | $document['_id'] = new \MongoId(); |
| 911 | 911 | } |
| 912 | 912 | |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | |
| 915 | 915 | return $document['_id']; |
| 916 | 916 | } elseif (is_object($document)) { |
| 917 | - if (! isset($document->_id)) { |
|
| 917 | + if ( ! isset($document->_id)) { |
|
| 918 | 918 | $document->_id = new \MongoId(); |
| 919 | 919 | } |
| 920 | 920 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function current() |
| 120 | 120 | { |
| 121 | - if (! $this->startedIterating) { |
|
| 121 | + if ( ! $this->startedIterating) { |
|
| 122 | 122 | return null; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function key() |
| 139 | 139 | { |
| 140 | - if (! $this->startedIterating) { |
|
| 140 | + if ( ! $this->startedIterating) { |
|
| 141 | 141 | return null; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function next() |
| 155 | 155 | { |
| 156 | - if (! $this->startedIterating) { |
|
| 156 | + if ( ! $this->startedIterating) { |
|
| 157 | 157 | $this->ensureIterator(); |
| 158 | 158 | $this->startedIterating = true; |
| 159 | 159 | } else { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | public function valid() |
| 188 | 188 | { |
| 189 | - if (! $this->startedIterating) { |
|
| 189 | + if ( ! $this->startedIterating) { |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | |