Skip to content

Commit 0cf95ce

Browse files
committed
PHPLIB-44: php-cs-fixer fix src/ --level=psr2
1 parent a04c7e1 commit 0cf95ce

File tree

4 files changed

+97
-59
lines changed

4 files changed

+97
-59
lines changed

src/Collection.php

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use MongoDB\WriteBatch;
1010
/* }}} */
1111

12-
class Collection {
12+
class Collection
13+
{
1314
const VERSION = "0.1.0";
1415

1516
/* {{{ consts & vars */
@@ -51,7 +52,8 @@ class Collection {
5152
* @param MongoDB\WriteConcern $wc The WriteConcern to apply to writes
5253
* @param MongoDB\ReadPreference $rp The ReadPreferences to apply to reads
5354
*/
54-
function __construct(Manager $manager, $ns, WriteConcern $wc = null, ReadPreference $rp = null) {
55+
public function __construct(Manager $manager, $ns, WriteConcern $wc = null, ReadPreference $rp = null)
56+
{
5557
$this->manager = $manager;
5658
$this->ns = $ns;
5759
$this->wc = $wc;
@@ -70,7 +72,8 @@ function __construct(Manager $manager, $ns, WriteConcern $wc = null, ReadPrefere
7072
* @param array $options Additional options
7173
* @return MongoDB\QueryResult
7274
*/
73-
function find(array $filter = array(), array $options = array()) {
75+
public function find(array $filter = array(), array $options = array())
76+
{
7477
$options = array_merge($this->getFindOptions(), $options);
7578

7679
$query = $this->_buildQuery($filter, $options);
@@ -90,7 +93,8 @@ function find(array $filter = array(), array $options = array()) {
9093
* @param array $options Additional options
9194
* @return array|false The matched document, or false on failure
9295
*/
93-
function findOne(array $filter = array(), array $options = array()) {
96+
public function findOne(array $filter = array(), array $options = array())
97+
{
9498
$options = array_merge($this->getFindOptions(), array("limit" => 1), $options);
9599

96100
$query = $this->_buildQuery($filter, $options);
@@ -110,7 +114,8 @@ function findOne(array $filter = array(), array $options = array()) {
110114
*
111115
* @return array of MongoDB\Collection::find() options
112116
*/
113-
function getFindOptions() {
117+
public function getFindOptions()
118+
{
114119
return array(
115120
/**
116121
* Get partial results from a mongos if some shards are down (instead of throwing an error).
@@ -214,7 +219,8 @@ function getFindOptions() {
214219
* @return integer OP_QUERY Wire Protocol flags
215220
* @internal
216221
*/
217-
final protected function _opQueryFlags($options) {
222+
final protected function _opQueryFlags($options)
223+
{
218224
$flags = 0;
219225

220226
$flags |= $options["allowPartialResults"] ? self::QUERY_FLAG_PARTIAL : 0;
@@ -233,7 +239,8 @@ final protected function _opQueryFlags($options) {
233239
* @return MongoDB\Query
234240
* @internal
235241
*/
236-
final protected function _buildQuery($filter, $options) {
242+
final protected function _buildQuery($filter, $options)
243+
{
237244
if ($options["comment"]) {
238245
$options["modifiers"]['$comment'] = $options["comment"];
239246
}
@@ -258,7 +265,8 @@ final protected function _buildQuery($filter, $options) {
258265
*
259266
* @return array of available Write options
260267
*/
261-
function getWriteOptions() {
268+
public function getWriteOptions()
269+
{
262270
return array(
263271
"ordered" => false,
264272
"upsert" => false,
@@ -271,7 +279,8 @@ function getWriteOptions() {
271279
*
272280
* @return array of available Bulk Write options
273281
*/
274-
function getBulkOptions() {
282+
public function getBulkOptions()
283+
{
275284
return array(
276285
"ordered" => false,
277286
);
@@ -324,18 +333,19 @@ function getBulkOptions() {
324333
* @param array $options Additional options
325334
* @return MongoDB\WriteResult
326335
*/
327-
function bulkWrite(array $bulk, array $options = array()) {
336+
public function bulkWrite(array $bulk, array $options = array())
337+
{
328338
$options = array_merge($this->getBulkOptions(), $options);
329339

330340
$batch = new WriteBatch($options["ordered"]);
331341

332-
foreach($bulk as $n => $op) {
333-
foreach($op as $opname => $args) {
342+
foreach ($bulk as $n => $op) {
343+
foreach ($op as $opname => $args) {
334344
if (!isset($args[0])) {
335345
throw new \InvalidArgumentException(sprintf("Missing argument#1 for '%s' (operation#%d)", $opname, $n));
336346
}
337347

338-
switch($opname) {
348+
switch ($opname) {
339349
case "insertOne":
340350
$batch->insert($args[0]);
341351
break;
@@ -401,7 +411,8 @@ function bulkWrite(array $bulk, array $options = array()) {
401411
* @param array $options Additional options
402412
* @return MongoDB\InsertResult
403413
*/
404-
function insertOne(array $document) {
414+
public function insertOne(array $document)
415+
{
405416
$options = array_merge($this->getWriteOptions());
406417

407418
$batch = new WriteBatch($options["ordered"]);
@@ -415,7 +426,8 @@ function insertOne(array $document) {
415426
* Internal helper for delete one/many documents
416427
* @internal
417428
*/
418-
final protected function _delete($filter, $limit = 1) {
429+
final protected function _delete($filter, $limit = 1)
430+
{
419431
$options = array_merge($this->getWriteOptions(), array("limit" => $limit));
420432

421433
$batch = new WriteBatch($options["ordered"]);
@@ -432,7 +444,8 @@ final protected function _delete($filter, $limit = 1) {
432444
* @param array $filter The $filter criteria to delete
433445
* @return MongoDB\DeleteResult
434446
*/
435-
function deleteOne(array $filter) {
447+
public function deleteOne(array $filter)
448+
{
436449
$wr = $this->_delete($filter);
437450

438451
return new DeleteResult($wr);
@@ -447,7 +460,8 @@ function deleteOne(array $filter) {
447460
* @param array $filter The $filter criteria to delete
448461
* @return MongoDB\DeleteResult
449462
*/
450-
function deleteMany(array $filter) {
463+
public function deleteMany(array $filter)
464+
{
451465
$wr = $this->_delete($filter, 0);
452466

453467
return new DeleteResult($wr);
@@ -457,7 +471,8 @@ function deleteMany(array $filter) {
457471
* Internal helper for replacing/updating one/many documents
458472
* @internal
459473
*/
460-
protected function _update($filter, $update, $options) {
474+
protected function _update($filter, $update, $options)
475+
{
461476
$options = array_merge($this->getWriteOptions(), $options);
462477

463478
$batch = new WriteBatch($options["ordered"]);
@@ -476,7 +491,8 @@ protected function _update($filter, $update, $options) {
476491
* @param array $options Additional options
477492
* @return MongoDB\UpdateResult
478493
*/
479-
function replaceOne(array $filter, array $update, array $options = array()) {
494+
public function replaceOne(array $filter, array $update, array $options = array())
495+
{
480496
if (key($update)[0] == '$') {
481497
throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator");
482498
}
@@ -497,7 +513,8 @@ function replaceOne(array $filter, array $update, array $options = array()) {
497513
* @param array $options Additional options
498514
* @return MongoDB\UpdateResult
499515
*/
500-
function updateOne(array $filter, array $update, array $options = array()) {
516+
public function updateOne(array $filter, array $update, array $options = array())
517+
{
501518
if (key($update)[0] != '$') {
502519
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
503520
}
@@ -518,7 +535,8 @@ function updateOne(array $filter, array $update, array $options = array()) {
518535
* @param array $options Additional options
519536
* @return MongoDB\UpdateResult
520537
*/
521-
function updateMany(array $filter, $update, array $options = array()) {
538+
public function updateMany(array $filter, $update, array $options = array())
539+
{
522540
$wr = $this->_update($filter, $update, $options + array("limit" => 0));
523541

524542
return new UpdateResult($wr);
@@ -535,7 +553,8 @@ function updateMany(array $filter, $update, array $options = array()) {
535553
* @param array $options Additional options
536554
* @return integer
537555
*/
538-
function count(array $filter = array(), array $options = array()) {
556+
public function count(array $filter = array(), array $options = array())
557+
{
539558
$cmd = array(
540559
"count" => $this->collname,
541560
"query" => $filter,
@@ -553,7 +572,8 @@ function count(array $filter = array(), array $options = array()) {
553572
*
554573
* @return array of MongoDB\Collection::count() options
555574
*/
556-
function getCountOptions() {
575+
public function getCountOptions()
576+
{
557577
return array(
558578
/**
559579
* The index to use.
@@ -596,7 +616,8 @@ function getCountOptions() {
596616
* @param array $options Additional options
597617
* @return integer
598618
*/
599-
function distinct($fieldName, array $filter = array(), array $options = array()) {
619+
public function distinct($fieldName, array $filter = array(), array $options = array())
620+
{
600621
$options = array_merge($this->getDistinctOptions(), $options);
601622
$cmd = array(
602623
"distinct" => $this->collname,
@@ -616,7 +637,8 @@ function distinct($fieldName, array $filter = array(), array $options = array())
616637
*
617638
* @return array of MongoDB\Collection::distinct() options
618639
*/
619-
function getDistinctOptions() {
640+
public function getDistinctOptions()
641+
{
620642
return array(
621643
/**
622644
* The maximum amount of time to allow the query to run. The default is infinite.
@@ -641,7 +663,8 @@ function getDistinctOptions() {
641663
* @param array $options Additional options
642664
* @return Iteratable
643665
*/
644-
function aggregate(array $pipeline, array $options = array()) {
666+
public function aggregate(array $pipeline, array $options = array())
667+
{
645668
$options = array_merge($this->getAggregateOptions(), $options);
646669
$options = $this->_massageAggregateOptions($options);
647670
$cmd = array(
@@ -667,7 +690,8 @@ function aggregate(array $pipeline, array $options = array()) {
667690
*
668691
* @return array of MongoDB\Collection::aggregate() options
669692
*/
670-
function getAggregateOptions() {
693+
public function getAggregateOptions()
694+
{
671695
$opts = array(
672696
/**
673697
* Enables writing to temporary files. When set to true, aggregation stages
@@ -714,7 +738,8 @@ function getAggregateOptions() {
714738
* Internal helper for massaging aggregate options
715739
* @internal
716740
*/
717-
protected function _massageAggregateOptions($options) {
741+
protected function _massageAggregateOptions($options)
742+
{
718743
if ($options["useCursor"]) {
719744
$options["cursor"] = array("batchSize" => $options["batchSize"]);
720745
}
@@ -733,7 +758,8 @@ protected function _massageAggregateOptions($options) {
733758
* @param array $options Additional options
734759
* @return array The original document
735760
*/
736-
function findOneAndDelete(array $filter, array $options = array()) {
761+
public function findOneAndDelete(array $filter, array $options = array())
762+
{
737763
$options = array_merge($this->getFindOneAndDeleteOptions(), $options);
738764
$options = $this->_massageFindAndModifyOptions($options);
739765
$cmd = array(
@@ -754,7 +780,8 @@ function findOneAndDelete(array $filter, array $options = array()) {
754780
*
755781
* @return array of MongoDB\Collection::findOneAndDelete() options
756782
*/
757-
function getFindOneAndDeleteOptions() {
783+
public function getFindOneAndDeleteOptions()
784+
{
758785
return array(
759786

760787
/**
@@ -794,7 +821,8 @@ function getFindOneAndDeleteOptions() {
794821
* @param array $options Additional options
795822
* @return array
796823
*/
797-
function findOneAndReplace(array $filter, array $replacement, array $options = array()) {
824+
public function findOneAndReplace(array $filter, array $replacement, array $options = array())
825+
{
798826
if (key($replacement)[0] == '$') {
799827
throw new \InvalidArgumentException("First key in \$replacement must NOT be a \$operator");
800828
}
@@ -820,7 +848,8 @@ function findOneAndReplace(array $filter, array $replacement, array $options = a
820848
*
821849
* @return array of MongoDB\Collection::findOneAndReplace() options
822850
*/
823-
function getFindOneAndReplaceOptions() {
851+
public function getFindOneAndReplaceOptions()
852+
{
824853
return array(
825854

826855
/**
@@ -860,7 +889,6 @@ function getFindOneAndReplaceOptions() {
860889
*/
861890
"upsert" => false,
862891
);
863-
864892
}
865893

866894
/**
@@ -878,7 +906,8 @@ function getFindOneAndReplaceOptions() {
878906
* @param array $options Additional options
879907
* @return array
880908
*/
881-
function findOneAndUpdate(array $filter, array $update, array $options = array()) {
909+
public function findOneAndUpdate(array $filter, array $update, array $options = array())
910+
{
882911
if (key($update)[0] != '$') {
883912
throw new \InvalidArgumentException("First key in \$update must be a \$operator");
884913
}
@@ -904,7 +933,8 @@ function findOneAndUpdate(array $filter, array $update, array $options = array()
904933
*
905934
* @return array of MongoDB\Collection::findOneAndUpdate() options
906935
*/
907-
function getFindOneAndUpdateOptions() {
936+
public function getFindOneAndUpdateOptions()
937+
{
908938
return array(
909939

910940
/**
@@ -943,14 +973,14 @@ function getFindOneAndUpdateOptions() {
943973
*/
944974
"upsert" => false,
945975
);
946-
947976
}
948977

949978
/**
950979
* Internal helper for massaging findandmodify options
951980
* @internal
952981
*/
953-
final protected function _massageFindAndModifyOptions($options, $update = array()) {
982+
final protected function _massageFindAndModifyOptions($options, $update = array())
983+
{
954984
$ret = array(
955985
"sort" => $options["sort"],
956986
"new" => isset($options["returnDocument"]) ? $options["returnDocument"] == self::FIND_ONE_AND_RETURN_AFTER : false,
@@ -970,7 +1000,8 @@ final protected function _massageFindAndModifyOptions($options, $update = array(
9701000
* Internal helper for throwing an exception with error message
9711001
* @internal
9721002
*/
973-
final protected function _generateCommandException($doc) {
1003+
final protected function _generateCommandException($doc)
1004+
{
9741005
if ($doc["errmsg"]) {
9751006
return new Exception($doc["errmsg"]);
9761007
}
@@ -982,7 +1013,8 @@ final protected function _generateCommandException($doc) {
9821013
* Internal helper for running a command
9831014
* @internal
9841015
*/
985-
final protected function _runCommand($dbname, array $cmd, ReadPreference $rp = null) {
1016+
final protected function _runCommand($dbname, array $cmd, ReadPreference $rp = null)
1017+
{
9861018
//var_dump(\BSON\toJSON(\BSON\fromArray($cmd)));
9871019
$command = new Command($cmd);
9881020
return $this->manager->executeCommand($dbname, $command, $rp);
@@ -993,7 +1025,8 @@ final protected function _runCommand($dbname, array $cmd, ReadPreference $rp = n
9931025
*
9941026
* @return string
9951027
*/
996-
function getCollectionName() {
1028+
public function getCollectionName()
1029+
{
9971030
return $this->collname;
9981031
}
9991032

@@ -1002,8 +1035,8 @@ function getCollectionName() {
10021035
*
10031036
* @return string
10041037
*/
1005-
function getDatabaseName() {
1038+
public function getDatabaseName()
1039+
{
10061040
return $this->dbname;
10071041
}
10081042
}
1009-

0 commit comments

Comments
 (0)