Completed
Pull Request — master (#187)
by Andreas
02:06
created
lib/Mongo/MongoClient.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
     use Helper\WriteConcern;
33 33
 
34 34
     const VERSION = '1.6.12';
35
-    const DEFAULT_HOST = "localhost" ;
36
-    const DEFAULT_PORT = 27017 ;
37
-    const RP_PRIMARY = "primary" ;
38
-    const RP_PRIMARY_PREFERRED = "primaryPreferred" ;
39
-    const RP_SECONDARY = "secondary" ;
40
-    const RP_SECONDARY_PREFERRED = "secondaryPreferred" ;
41
-    const RP_NEAREST = "nearest" ;
35
+    const DEFAULT_HOST = "localhost";
36
+    const DEFAULT_PORT = 27017;
37
+    const RP_PRIMARY = "primary";
38
+    const RP_PRIMARY_PREFERRED = "primaryPreferred";
39
+    const RP_SECONDARY = "secondary";
40
+    const RP_SECONDARY_PREFERRED = "secondaryPreferred";
41
+    const RP_NEAREST = "nearest";
42 42
 
43 43
     /**
44 44
      * @var bool
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 
91 91
         $this->server = $server;
92 92
         if (false === strpos($this->server, 'mongodb://')) {
93
-            $this->server = 'mongodb://'.$this->server;
93
+            $this->server = 'mongodb://' . $this->server;
94 94
         }
95 95
         $this->client = new Client($this->server, $options, $driverOptions);
96 96
         $info = $this->client->__debugInfo();
Please login to merge, or discard this patch.
lib/Mongo/MongoGridFS.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function findOne($query = [], array $fields = [], array $options = [])
133 133
     {
134
-        if (! is_array($query)) {
134
+        if ( ! is_array($query)) {
135 135
             $query = ['filename' => (string) $query];
136 136
         }
137 137
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
         try {
208 208
             $file = $this->insertFile($record, $options);
209 209
         } catch (MongoException $e) {
210
-            throw new MongoGridFSException('Could not store file: '. $e->getMessage(), $e->getCode(), $e);
210
+            throw new MongoGridFSException('Could not store file: ' . $e->getMessage(), $e->getCode(), $e);
211 211
         }
212 212
 
213 213
         try {
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
             ];
245 245
 
246 246
             $handle = fopen($filename, 'r');
247
-            if (! $handle) {
247
+            if ( ! $handle) {
248 248
                 throw new MongoGridFSException('could not open file: ' . $filename);
249 249
             }
250
-        } elseif (! is_resource($filename)) {
250
+        } elseif ( ! is_resource($filename)) {
251 251
             throw new \Exception('first argument must be a string or stream resource');
252 252
         } else {
253 253
             $handle = $filename;
@@ -270,10 +270,10 @@  discard block
 block discarded – undo
270 270
 
271 271
         // Add length and MD5 if they were not present before
272 272
         $update = [];
273
-        if (! isset($record['length'])) {
273
+        if ( ! isset($record['length'])) {
274 274
             $update['length'] = $length;
275 275
         }
276
-        if (! isset($record['md5'])) {
276
+        if ( ! isset($record['md5'])) {
277 277
             try {
278 278
                 $update['md5'] = $md5;
279 279
             } catch (MongoException $e) {
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
         if (count($update)) {
285 285
             try {
286 286
                 $result = $this->update(['_id' => $file['_id']], ['$set' => $update]);
287
-                if (! $this->isOKResult($result)) {
287
+                if ( ! $this->isOKResult($result)) {
288 288
                     throw new MongoGridFSException('Could not store file');
289 289
                 }
290 290
             } catch (MongoException $e) {
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
      */
308 308
     public function storeUpload($name, array $metadata = [])
309 309
     {
310
-        if (! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) {
310
+        if ( ! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) {
311 311
             throw new MongoGridFSException("Could not find uploaded file $name");
312 312
         }
313
-        if (! isset($_FILES[$name]['tmp_name'])) {
313
+        if ( ! isset($_FILES[$name]['tmp_name'])) {
314 314
             throw new MongoGridFSException("Couldn't find tmp_name in the \$_FILES array. Are you sure the upload worked?");
315 315
         }
316 316
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 
361 361
         $result = $this->chunks->insert($chunk);
362 362
 
363
-        if (! $this->isOKResult($result)) {
363
+        if ( ! $this->isOKResult($result)) {
364 364
             throw new \MongoException('error inserting chunk');
365 365
         }
366 366
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
         $hash = hash_init('md5');
406 406
 
407 407
         rewind($handle);
408
-        while (! feof($handle)) {
408
+        while ( ! feof($handle)) {
409 409
             $data = stream_get_contents($handle, $chunkSize);
410 410
             hash_update($hash, $data);
411 411
             $this->insertChunk($fileId, $data, $i++);
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 
436 436
         $result = $this->insert($record, $options);
437 437
 
438
-        if (! $this->isOKResult($result)) {
438
+        if ( ! $this->isOKResult($result)) {
439 439
             throw new \MongoException('error inserting file');
440 440
         }
441 441
 
Please login to merge, or discard this patch.
lib/Alcaeus/MongoDbAdapter/Helper/ReadPreference.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@
 block discarded – undo
110 110
                 return false;
111 111
         }
112 112
 
113
-        if ($readPreference == \MongoClient::RP_PRIMARY && !empty($tags)) {
113
+        if ($readPreference == \MongoClient::RP_PRIMARY && ! empty($tags)) {
114 114
             trigger_error("You can't use read preference tags with a read preference of PRIMARY", E_USER_WARNING);
115 115
             return false;
116 116
         }
Please login to merge, or discard this patch.
lib/Mongo/MongoDB.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             throw ExceptionConverter::toLegacy($e);
143 143
         }
144 144
 
145
-        $getCollectionInfo = function (CollectionInfo $collectionInfo) {
145
+        $getCollectionInfo = function(CollectionInfo $collectionInfo) {
146 146
             // @todo do away with __debugInfo once https://jira.mongodb.org/browse/PHPLIB-226 is fixed
147 147
             $info = $collectionInfo->__debugInfo();
148 148
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                     'info' => isset($info['info']) ? (array) $info['info'] : null,
155 155
                     'idIndex' => isset($info['idIndex']) ? (array) $info['idIndex'] : null,
156 156
                 ],
157
-                function ($item) { return $item !== null; }
157
+                function($item) { return $item !== null; }
158 158
             );
159 159
         };
160 160
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
             throw ExceptionConverter::toLegacy($e);
189 189
         }
190 190
 
191
-        $getCollectionName = function (CollectionInfo $collectionInfo) {
191
+        $getCollectionName = function(CollectionInfo $collectionInfo) {
192 192
             return $collectionInfo->getName();
193 193
         };
194 194
 
@@ -357,13 +357,13 @@  discard block
 block discarded – undo
357 357
         if ($document_or_id instanceof \MongoId) {
358 358
             $id = $document_or_id;
359 359
         } elseif (is_object($document_or_id)) {
360
-            if (! isset($document_or_id->_id)) {
360
+            if ( ! isset($document_or_id->_id)) {
361 361
                 $id = $document_or_id;
362 362
             } else {
363 363
                 $id = $document_or_id->_id;
364 364
             }
365 365
         } elseif (is_array($document_or_id)) {
366
-            if (! isset($document_or_id['_id'])) {
366
+            if ( ! isset($document_or_id['_id'])) {
367 367
                 return null;
368 368
             }
369 369
 
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
      */
552 552
     private function getSystemCollectionFilterClosure($includeSystemCollections = false)
553 553
     {
554
-        return function (CollectionInfo $collectionInfo) use ($includeSystemCollections) {
554
+        return function(CollectionInfo $collectionInfo) use ($includeSystemCollections) {
555 555
             return $includeSystemCollections || ! preg_match('#^system\.#', $collectionInfo->getName());
556 556
         };
557 557
     }
Please login to merge, or discard this patch.
lib/Alcaeus/MongoDbAdapter/TypeConverter.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -103,16 +103,16 @@
 block discarded – undo
103 103
      */
104 104
     public static function convertProjection($fields)
105 105
     {
106
-        if (! is_array($fields) || $fields === []) {
106
+        if ( ! is_array($fields) || $fields === []) {
107 107
             return null;
108 108
         }
109 109
 
110
-        if (! TypeConverter::isNumericArray($fields)) {
110
+        if ( ! TypeConverter::isNumericArray($fields)) {
111 111
             $projection = TypeConverter::fromLegacy($fields);
112 112
         } else {
113 113
             $projection = array_fill_keys(
114
-                array_map(function ($field) {
115
-                    if (!is_string($field)) {
114
+                array_map(function($field) {
115
+                    if ( ! is_string($field)) {
116 116
                         throw new \MongoException('field names must be strings', 8);
117 117
                     }
118 118
 
Please login to merge, or discard this patch.
lib/Mongo/MongoCollection.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
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
             $operators = func_get_args();
135 135
             $pipeline = [];
136 136
             $options = [];
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
             $i = 0;
139 139
             foreach ($operators as $operator) {
140 140
                 $i++;
141
-                if (! is_array($operator)) {
141
+                if ( ! is_array($operator)) {
142 142
                     trigger_error("Argument $i is not an array", E_USER_WARNING);
143 143
                     return;
144 144
                 }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         ];
192 192
 
193 193
         // Convert cursor option
194
-        if (! isset($options['cursor'])) {
194
+        if ( ! isset($options['cursor'])) {
195 195
             $options['cursor'] = new \stdClass();
196 196
         }
197 197
 
@@ -277,12 +277,12 @@  discard block
 block discarded – undo
277 277
      */
278 278
     public function insert(&$a, array $options = [])
279 279
     {
280
-        if (! $this->ensureDocumentHasMongoId($a)) {
280
+        if ( ! $this->ensureDocumentHasMongoId($a)) {
281 281
             trigger_error(sprintf('%s(): expects parameter %d to be an array or object, %s given', __METHOD__, 1, gettype($a)), E_USER_WARNING);
282 282
             return;
283 283
         }
284 284
 
285
-        if (! count((array)$a)) {
285
+        if ( ! count((array) $a)) {
286 286
             throw new \MongoException('document must be an array or object');
287 287
         }
288 288
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             throw ExceptionConverter::toLegacy($e);
296 296
         }
297 297
 
298
-        if (! $result->isAcknowledged()) {
298
+        if ( ! $result->isAcknowledged()) {
299 299
             return true;
300 300
         }
301 301
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 
327 327
         foreach ($a as $key => $item) {
328 328
             try {
329
-                if (! $this->ensureDocumentHasMongoId($a[$key])) {
329
+                if ( ! $this->ensureDocumentHasMongoId($a[$key])) {
330 330
                     if ($continueOnError) {
331 331
                         unset($a[$key]);
332 332
                     } else {
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
                     }
336 336
                 }
337 337
             } catch (MongoException $e) {
338
-                if (! $continueOnError) {
338
+                if ( ! $continueOnError) {
339 339
                     throw $e;
340 340
                 }
341 341
             }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             throw ExceptionConverter::toLegacy($e, 'MongoResultException');
351 351
         }
352 352
 
353
-        if (! $result->isAcknowledged()) {
353
+        if ( ! $result->isAcknowledged()) {
354 354
             return true;
355 355
         }
356 356
 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
             throw ExceptionConverter::toLegacy($e);
401 401
         }
402 402
 
403
-        if (! $result->isAcknowledged()) {
403
+        if ( ! $result->isAcknowledged()) {
404 404
             return true;
405 405
         }
406 406
 
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
      */
428 428
     public function remove(array $criteria = [], array $options = [])
429 429
     {
430
-        $multiple = isset($options['justOne']) ? !$options['justOne'] : true;
430
+        $multiple = isset($options['justOne']) ? ! $options['justOne'] : true;
431 431
         $method = $multiple ? 'deleteMany' : 'deleteOne';
432 432
 
433 433
         try {
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
             throw ExceptionConverter::toLegacy($e);
441 441
         }
442 442
 
443
-        if (! $result->isAcknowledged()) {
443
+        if ( ! $result->isAcknowledged()) {
444 444
             return true;
445 445
         }
446 446
 
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 
519 519
                 $options['projection'] = TypeConverter::convertProjection($fields);
520 520
 
521
-                if (! \MongoDB\is_first_key_operator($update)) {
521
+                if ( ! \MongoDB\is_first_key_operator($update)) {
522 522
                     $document = $this->collection->findOneAndReplace($query, $update, $options);
523 523
                 } else {
524 524
                     $document = $this->collection->findOneAndUpdate($query, $update, $options);
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
     public function findOne($query = [], array $fields = [], array $options = [])
550 550
     {
551 551
         // Can't typehint for array since MongoGridFS extends and accepts strings
552
-        if (! is_array($query)) {
552
+        if ( ! is_array($query)) {
553 553
             trigger_error(sprintf('MongoCollection::findOne(): expects parameter 1 to be an array or object, %s given', gettype($query)), E_USER_WARNING);
554 554
             return;
555 555
         }
@@ -589,11 +589,11 @@  discard block
 block discarded – undo
589 589
             $keys = (array) $keys;
590 590
         }
591 591
 
592
-        if (! is_array($keys) || ! count($keys)) {
592
+        if ( ! is_array($keys) || ! count($keys)) {
593 593
             throw new MongoException('index specification has no elements');
594 594
         }
595 595
 
596
-        if (! isset($options['name'])) {
596
+        if ( ! isset($options['name'])) {
597 597
             $options['name'] = \MongoDB\generate_index_name($keys);
598 598
         }
599 599
 
@@ -628,14 +628,14 @@  discard block
 block discarded – undo
628 628
         }
629 629
 
630 630
         $result = [
631
-            'createdCollectionAutomatically' => !$collectionExists,
631
+            'createdCollectionAutomatically' => ! $collectionExists,
632 632
             'numIndexesBefore' => $indexCount,
633 633
             'numIndexesAfter' => $indexCount,
634 634
             'note' => 'all indexes already exist',
635 635
             'ok' => 1.0,
636 636
         ];
637 637
 
638
-        if (! $indexExists) {
638
+        if ( ! $indexExists) {
639 639
             $result['numIndexesAfter']++;
640 640
             unset($result['note']);
641 641
         }
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
     {
669 669
         if (is_string($keys)) {
670 670
             $indexName = $keys;
671
-            if (! preg_match('#_-?1$#', $indexName)) {
671
+            if ( ! preg_match('#_-?1$#', $indexName)) {
672 672
                 $indexName .= '_1';
673 673
             }
674 674
         } elseif (is_array($keys)) {
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
      */
708 708
     public function getIndexInfo()
709 709
     {
710
-        $convertIndex = function (\MongoDB\Model\IndexInfo $indexInfo) {
710
+        $convertIndex = function(\MongoDB\Model\IndexInfo $indexInfo) {
711 711
             $infos = [
712 712
                 'v' => $indexInfo->getVersion(),
713 713
                 'key' => $indexInfo->getKey(),
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
             ];
732 732
 
733 733
             foreach ($additionalKeys as $key) {
734
-                if (! isset($indexInfo[$key])) {
734
+                if ( ! isset($indexInfo[$key])) {
735 735
                     continue;
736 736
                 }
737 737
 
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     {
757 757
         try {
758 758
             // Handle legacy mode - limit and skip as second and third parameters, respectively
759
-            if (! is_array($options)) {
759
+            if ( ! is_array($options)) {
760 760
                 $limit = $options;
761 761
                 $options = [];
762 762
 
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
                 $this->convertWriteConcernOptions($options)
804 804
             );
805 805
 
806
-            if (! $result->isAcknowledged()) {
806
+            if ( ! $result->isAcknowledged()) {
807 807
                 return true;
808 808
             }
809 809
 
@@ -837,13 +837,13 @@  discard block
 block discarded – undo
837 837
         if ($document_or_id instanceof \MongoId) {
838 838
             $id = $document_or_id;
839 839
         } elseif (is_object($document_or_id)) {
840
-            if (! isset($document_or_id->_id)) {
840
+            if ( ! isset($document_or_id->_id)) {
841 841
                 return null;
842 842
             }
843 843
 
844 844
             $id = $document_or_id->_id;
845 845
         } elseif (is_array($document_or_id)) {
846
-            if (! isset($document_or_id['_id'])) {
846
+            if ( ! isset($document_or_id['_id'])) {
847 847
                 return null;
848 848
             }
849 849
 
@@ -886,14 +886,14 @@  discard block
 block discarded – undo
886 886
         $command = [
887 887
             'group' => [
888 888
                 'ns' => $this->name,
889
-                '$reduce' => (string)$reduce,
889
+                '$reduce' => (string) $reduce,
890 890
                 'initial' => $initial,
891 891
                 'cond' => $condition,
892 892
             ],
893 893
         ];
894 894
 
895 895
         if ($keys instanceof MongoCode) {
896
-            $command['group']['$keyf'] = (string)$keys;
896
+            $command['group']['$keyf'] = (string) $keys;
897 897
         } else {
898 898
             $command['group']['key'] = $keys;
899 899
         }
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
         }
903 903
         if (array_key_exists('finalize', $condition)) {
904 904
             if ($condition['finalize'] instanceof MongoCode) {
905
-                $condition['finalize'] = (string)$condition['finalize'];
905
+                $condition['finalize'] = (string) $condition['finalize'];
906 906
             }
907 907
             $command['group']['finalize'] = $condition['finalize'];
908 908
         }
@@ -956,11 +956,11 @@  discard block
 block discarded – undo
956 956
             $options['w'] = ($options['safe']) ? 1 : 0;
957 957
         }
958 958
 
959
-        if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) {
959
+        if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) {
960 960
             $options['wTimeoutMS'] = $options['wtimeout'];
961 961
         }
962 962
 
963
-        if (isset($options['w']) || !isset($options['wTimeoutMS'])) {
963
+        if (isset($options['w']) || ! isset($options['wTimeoutMS'])) {
964 964
             $collectionWriteConcern = $this->getWriteConcern();
965 965
             $writeConcern = $this->createWriteConcernFromParameters(
966 966
                 isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'],
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
     private function ensureDocumentHasMongoId(&$document)
995 995
     {
996 996
         if (is_array($document)) {
997
-            if (! isset($document['_id'])) {
997
+            if ( ! isset($document['_id'])) {
998 998
                 $document['_id'] = new \MongoId();
999 999
             }
1000 1000
 
@@ -1004,12 +1004,12 @@  discard block
 block discarded – undo
1004 1004
         } elseif (is_object($document)) {
1005 1005
             $reflectionObject = new \ReflectionObject($document);
1006 1006
             foreach ($reflectionObject->getProperties() as $property) {
1007
-                if (! $property->isPublic()) {
1007
+                if ( ! $property->isPublic()) {
1008 1008
                     throw new \MongoException('zero-length keys are not allowed, did you use $ with double quotes?');
1009 1009
                 }
1010 1010
             }
1011 1011
 
1012
-            if (! isset($document->_id)) {
1012
+            if ( ! isset($document->_id)) {
1013 1013
                 $document->_id = new \MongoId();
1014 1014
             }
1015 1015
 
Please login to merge, or discard this patch.
lib/Mongo/MongoCommandCursor.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
             }
66 66
 
67 67
             $originalReadPreference = null;
68
-            if (!$this->supportsReadPreference()) {
68
+            if ( ! $this->supportsReadPreference()) {
69 69
                 $originalReadPreference = $this->readPreference;
70 70
                 $this->setReadPreference(\MongoClient::RP_PRIMARY);
71 71
             }
Please login to merge, or discard this patch.