Completed
Pull Request — master (#178)
by
unknown
05:24
created
lib/Mongo/MongoGridFSFile.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             $filename = 'file';
79 79
         }
80 80
 
81
-        if (! $handle = fopen($filename, 'w')) {
81
+        if ( ! $handle = fopen($filename, 'w')) {
82 82
             trigger_error('Can not open the destination file', E_USER_ERROR);
83 83
             return 0;
84 84
         }
Please login to merge, or discard this patch.
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/MongoDB.php 1 patch
Spacing   +5 added lines, -5 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
             return [
147 147
                 'name' => $collectionInfo->getName(),
148 148
                 'options' => $collectionInfo->getOptions(),
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
             throw ExceptionConverter::toLegacy($e);
180 180
         }
181 181
 
182
-        $getCollectionName = function (CollectionInfo $collectionInfo) {
182
+        $getCollectionName = function(CollectionInfo $collectionInfo) {
183 183
             return $collectionInfo->getName();
184 184
         };
185 185
 
@@ -348,13 +348,13 @@  discard block
 block discarded – undo
348 348
         if ($document_or_id instanceof \MongoId) {
349 349
             $id = $document_or_id;
350 350
         } elseif (is_object($document_or_id)) {
351
-            if (! isset($document_or_id->_id)) {
351
+            if ( ! isset($document_or_id->_id)) {
352 352
                 $id = $document_or_id;
353 353
             } else {
354 354
                 $id = $document_or_id->_id;
355 355
             }
356 356
         } elseif (is_array($document_or_id)) {
357
-            if (! isset($document_or_id['_id'])) {
357
+            if ( ! isset($document_or_id['_id'])) {
358 358
                 return null;
359 359
             }
360 360
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
      */
543 543
     private function getSystemCollectionFilterClosure($includeSystemCollections = false)
544 544
     {
545
-        return function (CollectionInfo $collectionInfo) use ($includeSystemCollections) {
545
+        return function(CollectionInfo $collectionInfo) use ($includeSystemCollections) {
546 546
             return $includeSystemCollections || ! preg_match('#^system\.#', $collectionInfo->getName());
547 547
         };
548 548
     }
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/Mongo/MongoCollection.php 1 patch
Spacing   +36 added lines, -36 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
 
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
             throw ExceptionConverter::toLegacy($e);
399 399
         }
400 400
 
401
-        if (! $result->isAcknowledged()) {
401
+        if ( ! $result->isAcknowledged()) {
402 402
             return true;
403 403
         }
404 404
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
      */
426 426
     public function remove(array $criteria = [], array $options = [])
427 427
     {
428
-        $multiple = isset($options['justOne']) ? !$options['justOne'] : true;
428
+        $multiple = isset($options['justOne']) ? ! $options['justOne'] : true;
429 429
         $method = $multiple ? 'deleteMany' : 'deleteOne';
430 430
 
431 431
         try {
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
             throw ExceptionConverter::toLegacy($e);
439 439
         }
440 440
 
441
-        if (! $result->isAcknowledged()) {
441
+        if ( ! $result->isAcknowledged()) {
442 442
             return true;
443 443
         }
444 444
 
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 
517 517
                 $options['projection'] = TypeConverter::convertProjection($fields);
518 518
 
519
-                if (! \MongoDB\is_first_key_operator($update)) {
519
+                if ( ! \MongoDB\is_first_key_operator($update)) {
520 520
                     $document = $this->collection->findOneAndReplace($query, $update, $options);
521 521
                 } else {
522 522
                     $document = $this->collection->findOneAndUpdate($query, $update, $options);
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
     public function findOne($query = [], array $fields = [], array $options = [])
548 548
     {
549 549
         // Can't typehint for array since MongoGridFS extends and accepts strings
550
-        if (! is_array($query)) {
550
+        if ( ! is_array($query)) {
551 551
             trigger_error(sprintf('MongoCollection::findOne(): expects parameter 1 to be an array or object, %s given', gettype($query)), E_USER_WARNING);
552 552
             return;
553 553
         }
@@ -587,11 +587,11 @@  discard block
 block discarded – undo
587 587
             $keys = (array) $keys;
588 588
         }
589 589
 
590
-        if (! is_array($keys) || ! count($keys)) {
590
+        if ( ! is_array($keys) || ! count($keys)) {
591 591
             throw new MongoException('index specification has no elements');
592 592
         }
593 593
 
594
-        if (! isset($options['name'])) {
594
+        if ( ! isset($options['name'])) {
595 595
             $options['name'] = \MongoDB\generate_index_name($keys);
596 596
         }
597 597
 
@@ -626,14 +626,14 @@  discard block
 block discarded – undo
626 626
         }
627 627
 
628 628
         $result = [
629
-            'createdCollectionAutomatically' => !$collectionExists,
629
+            'createdCollectionAutomatically' => ! $collectionExists,
630 630
             'numIndexesBefore' => $indexCount,
631 631
             'numIndexesAfter' => $indexCount,
632 632
             'note' => 'all indexes already exist',
633 633
             'ok' => 1.0,
634 634
         ];
635 635
 
636
-        if (! $indexExists) {
636
+        if ( ! $indexExists) {
637 637
             $result['numIndexesAfter']++;
638 638
             unset($result['note']);
639 639
         }
@@ -667,13 +667,13 @@  discard block
 block discarded – undo
667 667
     {
668 668
         if (is_string($keys)) {
669 669
             $indexName = $keys;
670
-            if (!$keysAsIndexNames) {
671
-                if (!preg_match('#_-?1$#', $indexName)) {
670
+            if ( ! $keysAsIndexNames) {
671
+                if ( ! preg_match('#_-?1$#', $indexName)) {
672 672
                     $indexName .= '_1';
673 673
                 }
674 674
             }
675 675
         } elseif (is_array($keys)) {
676
-            if (!$keysAsIndexNames) {
676
+            if ( ! $keysAsIndexNames) {
677 677
                 $indexName = \MongoDB\generate_index_name($keys);
678 678
             }
679 679
         } else {
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
      */
711 711
     public function getIndexInfo()
712 712
     {
713
-        $convertIndex = function (\MongoDB\Model\IndexInfo $indexInfo) {
713
+        $convertIndex = function(\MongoDB\Model\IndexInfo $indexInfo) {
714 714
             $infos = [
715 715
                 'v' => $indexInfo->getVersion(),
716 716
                 'key' => $indexInfo->getKey(),
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             ];
735 735
 
736 736
             foreach ($additionalKeys as $key) {
737
-                if (! isset($indexInfo[$key])) {
737
+                if ( ! isset($indexInfo[$key])) {
738 738
                     continue;
739 739
                 }
740 740
 
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
     {
760 760
         try {
761 761
             // Handle legacy mode - limit and skip as second and third parameters, respectively
762
-            if (! is_array($options)) {
762
+            if ( ! is_array($options)) {
763 763
                 $limit = $options;
764 764
                 $options = [];
765 765
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
                 $this->convertWriteConcernOptions($options)
807 807
             );
808 808
 
809
-            if (! $result->isAcknowledged()) {
809
+            if ( ! $result->isAcknowledged()) {
810 810
                 return true;
811 811
             }
812 812
 
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
         if ($document_or_id instanceof \MongoId) {
841 841
             $id = $document_or_id;
842 842
         } elseif (is_object($document_or_id)) {
843
-            if (! isset($document_or_id->_id)) {
843
+            if ( ! isset($document_or_id->_id)) {
844 844
                 return null;
845 845
             }
846 846
 
847 847
             $id = $document_or_id->_id;
848 848
         } elseif (is_array($document_or_id)) {
849
-            if (! isset($document_or_id['_id'])) {
849
+            if ( ! isset($document_or_id['_id'])) {
850 850
                 return null;
851 851
             }
852 852
 
@@ -889,14 +889,14 @@  discard block
 block discarded – undo
889 889
         $command = [
890 890
             'group' => [
891 891
                 'ns' => $this->name,
892
-                '$reduce' => (string)$reduce,
892
+                '$reduce' => (string) $reduce,
893 893
                 'initial' => $initial,
894 894
                 'cond' => $condition,
895 895
             ],
896 896
         ];
897 897
 
898 898
         if ($keys instanceof MongoCode) {
899
-            $command['group']['$keyf'] = (string)$keys;
899
+            $command['group']['$keyf'] = (string) $keys;
900 900
         } else {
901 901
             $command['group']['key'] = $keys;
902 902
         }
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
         }
906 906
         if (array_key_exists('finalize', $condition)) {
907 907
             if ($condition['finalize'] instanceof MongoCode) {
908
-                $condition['finalize'] = (string)$condition['finalize'];
908
+                $condition['finalize'] = (string) $condition['finalize'];
909 909
             }
910 910
             $command['group']['finalize'] = $condition['finalize'];
911 911
         }
@@ -959,11 +959,11 @@  discard block
 block discarded – undo
959 959
             $options['w'] = ($options['safe']) ? 1 : 0;
960 960
         }
961 961
 
962
-        if (isset($options['wtimeout']) && !isset($options['wTimeoutMS'])) {
962
+        if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) {
963 963
             $options['wTimeoutMS'] = $options['wtimeout'];
964 964
         }
965 965
 
966
-        if (isset($options['w']) || !isset($options['wTimeoutMS'])) {
966
+        if (isset($options['w']) || ! isset($options['wTimeoutMS'])) {
967 967
             $collectionWriteConcern = $this->getWriteConcern();
968 968
             $writeConcern = $this->createWriteConcernFromParameters(
969 969
                 isset($options['w']) ? $options['w'] : $collectionWriteConcern['w'],
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
      */
988 988
     private function ensureDocumentHasMongoId(&$document)
989 989
     {
990
-        $checkKeys = function ($array) {
990
+        $checkKeys = function($array) {
991 991
             foreach (array_keys($array) as $key) {
992 992
                 if (empty($key) && $key !== 0) {
993 993
                     throw new \MongoException('zero-length keys are not allowed, did you use $ with double quotes?');
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
         };
997 997
 
998 998
         if (is_array($document)) {
999
-            if (! isset($document['_id'])) {
999
+            if ( ! isset($document['_id'])) {
1000 1000
                 $document['_id'] = new \MongoId();
1001 1001
             }
1002 1002
 
@@ -1006,12 +1006,12 @@  discard block
 block discarded – undo
1006 1006
         } elseif (is_object($document)) {
1007 1007
             $reflectionObject = new \ReflectionObject($document);
1008 1008
             foreach ($reflectionObject->getProperties() as $property) {
1009
-                if (! $property->isPublic()) {
1009
+                if ( ! $property->isPublic()) {
1010 1010
                     throw new \MongoException('zero-length keys are not allowed, did you use $ with double quotes?');
1011 1011
                 }
1012 1012
             }
1013 1013
 
1014
-            if (! isset($document->_id)) {
1014
+            if ( ! isset($document->_id)) {
1015 1015
                 $document->_id = new \MongoId();
1016 1016
             }
1017 1017
 
Please login to merge, or discard this patch.