Commit 0cf95ce2 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-44: php-cs-fixer fix src/ --level=psr2

parent a04c7e14
...@@ -9,7 +9,8 @@ use MongoDB\ReadPreference; ...@@ -9,7 +9,8 @@ use MongoDB\ReadPreference;
use MongoDB\WriteBatch; use MongoDB\WriteBatch;
/* }}} */ /* }}} */
class Collection { class Collection
{
const VERSION = "0.1.0"; const VERSION = "0.1.0";
/* {{{ consts & vars */ /* {{{ consts & vars */
...@@ -51,7 +52,8 @@ class Collection { ...@@ -51,7 +52,8 @@ class Collection {
* @param MongoDB\WriteConcern $wc The WriteConcern to apply to writes * @param MongoDB\WriteConcern $wc The WriteConcern to apply to writes
* @param MongoDB\ReadPreference $rp The ReadPreferences to apply to reads * @param MongoDB\ReadPreference $rp The ReadPreferences to apply to reads
*/ */
function __construct(Manager $manager, $ns, WriteConcern $wc = null, ReadPreference $rp = null) { public function __construct(Manager $manager, $ns, WriteConcern $wc = null, ReadPreference $rp = null)
{
$this->manager = $manager; $this->manager = $manager;
$this->ns = $ns; $this->ns = $ns;
$this->wc = $wc; $this->wc = $wc;
...@@ -70,7 +72,8 @@ class Collection { ...@@ -70,7 +72,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return MongoDB\QueryResult * @return MongoDB\QueryResult
*/ */
function find(array $filter = array(), array $options = array()) { public function find(array $filter = array(), array $options = array())
{
$options = array_merge($this->getFindOptions(), $options); $options = array_merge($this->getFindOptions(), $options);
$query = $this->_buildQuery($filter, $options); $query = $this->_buildQuery($filter, $options);
...@@ -90,7 +93,8 @@ class Collection { ...@@ -90,7 +93,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return array|false The matched document, or false on failure * @return array|false The matched document, or false on failure
*/ */
function findOne(array $filter = array(), array $options = array()) { public function findOne(array $filter = array(), array $options = array())
{
$options = array_merge($this->getFindOptions(), array("limit" => 1), $options); $options = array_merge($this->getFindOptions(), array("limit" => 1), $options);
$query = $this->_buildQuery($filter, $options); $query = $this->_buildQuery($filter, $options);
...@@ -110,7 +114,8 @@ class Collection { ...@@ -110,7 +114,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::find() options * @return array of MongoDB\Collection::find() options
*/ */
function getFindOptions() { public function getFindOptions()
{
return array( return array(
/** /**
* Get partial results from a mongos if some shards are down (instead of throwing an error). * Get partial results from a mongos if some shards are down (instead of throwing an error).
...@@ -214,7 +219,8 @@ class Collection { ...@@ -214,7 +219,8 @@ class Collection {
* @return integer OP_QUERY Wire Protocol flags * @return integer OP_QUERY Wire Protocol flags
* @internal * @internal
*/ */
final protected function _opQueryFlags($options) { final protected function _opQueryFlags($options)
{
$flags = 0; $flags = 0;
$flags |= $options["allowPartialResults"] ? self::QUERY_FLAG_PARTIAL : 0; $flags |= $options["allowPartialResults"] ? self::QUERY_FLAG_PARTIAL : 0;
...@@ -233,7 +239,8 @@ class Collection { ...@@ -233,7 +239,8 @@ class Collection {
* @return MongoDB\Query * @return MongoDB\Query
* @internal * @internal
*/ */
final protected function _buildQuery($filter, $options) { final protected function _buildQuery($filter, $options)
{
if ($options["comment"]) { if ($options["comment"]) {
$options["modifiers"]['$comment'] = $options["comment"]; $options["modifiers"]['$comment'] = $options["comment"];
} }
...@@ -258,7 +265,8 @@ class Collection { ...@@ -258,7 +265,8 @@ class Collection {
* *
* @return array of available Write options * @return array of available Write options
*/ */
function getWriteOptions() { public function getWriteOptions()
{
return array( return array(
"ordered" => false, "ordered" => false,
"upsert" => false, "upsert" => false,
...@@ -271,7 +279,8 @@ class Collection { ...@@ -271,7 +279,8 @@ class Collection {
* *
* @return array of available Bulk Write options * @return array of available Bulk Write options
*/ */
function getBulkOptions() { public function getBulkOptions()
{
return array( return array(
"ordered" => false, "ordered" => false,
); );
...@@ -324,18 +333,19 @@ class Collection { ...@@ -324,18 +333,19 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return MongoDB\WriteResult * @return MongoDB\WriteResult
*/ */
function bulkWrite(array $bulk, array $options = array()) { public function bulkWrite(array $bulk, array $options = array())
{
$options = array_merge($this->getBulkOptions(), $options); $options = array_merge($this->getBulkOptions(), $options);
$batch = new WriteBatch($options["ordered"]); $batch = new WriteBatch($options["ordered"]);
foreach($bulk as $n => $op) { foreach ($bulk as $n => $op) {
foreach($op as $opname => $args) { foreach ($op as $opname => $args) {
if (!isset($args[0])) { if (!isset($args[0])) {
throw new \InvalidArgumentException(sprintf("Missing argument#1 for '%s' (operation#%d)", $opname, $n)); throw new \InvalidArgumentException(sprintf("Missing argument#1 for '%s' (operation#%d)", $opname, $n));
} }
switch($opname) { switch ($opname) {
case "insertOne": case "insertOne":
$batch->insert($args[0]); $batch->insert($args[0]);
break; break;
...@@ -401,7 +411,8 @@ class Collection { ...@@ -401,7 +411,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return MongoDB\InsertResult * @return MongoDB\InsertResult
*/ */
function insertOne(array $document) { public function insertOne(array $document)
{
$options = array_merge($this->getWriteOptions()); $options = array_merge($this->getWriteOptions());
$batch = new WriteBatch($options["ordered"]); $batch = new WriteBatch($options["ordered"]);
...@@ -415,7 +426,8 @@ class Collection { ...@@ -415,7 +426,8 @@ class Collection {
* Internal helper for delete one/many documents * Internal helper for delete one/many documents
* @internal * @internal
*/ */
final protected function _delete($filter, $limit = 1) { final protected function _delete($filter, $limit = 1)
{
$options = array_merge($this->getWriteOptions(), array("limit" => $limit)); $options = array_merge($this->getWriteOptions(), array("limit" => $limit));
$batch = new WriteBatch($options["ordered"]); $batch = new WriteBatch($options["ordered"]);
...@@ -432,7 +444,8 @@ class Collection { ...@@ -432,7 +444,8 @@ class Collection {
* @param array $filter The $filter criteria to delete * @param array $filter The $filter criteria to delete
* @return MongoDB\DeleteResult * @return MongoDB\DeleteResult
*/ */
function deleteOne(array $filter) { public function deleteOne(array $filter)
{
$wr = $this->_delete($filter); $wr = $this->_delete($filter);
return new DeleteResult($wr); return new DeleteResult($wr);
...@@ -447,7 +460,8 @@ class Collection { ...@@ -447,7 +460,8 @@ class Collection {
* @param array $filter The $filter criteria to delete * @param array $filter The $filter criteria to delete
* @return MongoDB\DeleteResult * @return MongoDB\DeleteResult
*/ */
function deleteMany(array $filter) { public function deleteMany(array $filter)
{
$wr = $this->_delete($filter, 0); $wr = $this->_delete($filter, 0);
return new DeleteResult($wr); return new DeleteResult($wr);
...@@ -457,7 +471,8 @@ class Collection { ...@@ -457,7 +471,8 @@ class Collection {
* Internal helper for replacing/updating one/many documents * Internal helper for replacing/updating one/many documents
* @internal * @internal
*/ */
protected function _update($filter, $update, $options) { protected function _update($filter, $update, $options)
{
$options = array_merge($this->getWriteOptions(), $options); $options = array_merge($this->getWriteOptions(), $options);
$batch = new WriteBatch($options["ordered"]); $batch = new WriteBatch($options["ordered"]);
...@@ -476,7 +491,8 @@ class Collection { ...@@ -476,7 +491,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return MongoDB\UpdateResult * @return MongoDB\UpdateResult
*/ */
function replaceOne(array $filter, array $update, array $options = array()) { public function replaceOne(array $filter, array $update, array $options = array())
{
if (key($update)[0] == '$') { if (key($update)[0] == '$') {
throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator"); throw new \InvalidArgumentException("First key in \$update must NOT be a \$operator");
} }
...@@ -497,7 +513,8 @@ class Collection { ...@@ -497,7 +513,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return MongoDB\UpdateResult * @return MongoDB\UpdateResult
*/ */
function updateOne(array $filter, array $update, array $options = array()) { public function updateOne(array $filter, array $update, array $options = array())
{
if (key($update)[0] != '$') { if (key($update)[0] != '$') {
throw new \InvalidArgumentException("First key in \$update must be a \$operator"); throw new \InvalidArgumentException("First key in \$update must be a \$operator");
} }
...@@ -518,7 +535,8 @@ class Collection { ...@@ -518,7 +535,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return MongoDB\UpdateResult * @return MongoDB\UpdateResult
*/ */
function updateMany(array $filter, $update, array $options = array()) { public function updateMany(array $filter, $update, array $options = array())
{
$wr = $this->_update($filter, $update, $options + array("limit" => 0)); $wr = $this->_update($filter, $update, $options + array("limit" => 0));
return new UpdateResult($wr); return new UpdateResult($wr);
...@@ -535,7 +553,8 @@ class Collection { ...@@ -535,7 +553,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return integer * @return integer
*/ */
function count(array $filter = array(), array $options = array()) { public function count(array $filter = array(), array $options = array())
{
$cmd = array( $cmd = array(
"count" => $this->collname, "count" => $this->collname,
"query" => $filter, "query" => $filter,
...@@ -553,7 +572,8 @@ class Collection { ...@@ -553,7 +572,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::count() options * @return array of MongoDB\Collection::count() options
*/ */
function getCountOptions() { public function getCountOptions()
{
return array( return array(
/** /**
* The index to use. * The index to use.
...@@ -596,7 +616,8 @@ class Collection { ...@@ -596,7 +616,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return integer * @return integer
*/ */
function distinct($fieldName, array $filter = array(), array $options = array()) { public function distinct($fieldName, array $filter = array(), array $options = array())
{
$options = array_merge($this->getDistinctOptions(), $options); $options = array_merge($this->getDistinctOptions(), $options);
$cmd = array( $cmd = array(
"distinct" => $this->collname, "distinct" => $this->collname,
...@@ -616,7 +637,8 @@ class Collection { ...@@ -616,7 +637,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::distinct() options * @return array of MongoDB\Collection::distinct() options
*/ */
function getDistinctOptions() { public function getDistinctOptions()
{
return array( return array(
/** /**
* The maximum amount of time to allow the query to run. The default is infinite. * The maximum amount of time to allow the query to run. The default is infinite.
...@@ -641,7 +663,8 @@ class Collection { ...@@ -641,7 +663,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return Iteratable * @return Iteratable
*/ */
function aggregate(array $pipeline, array $options = array()) { public function aggregate(array $pipeline, array $options = array())
{
$options = array_merge($this->getAggregateOptions(), $options); $options = array_merge($this->getAggregateOptions(), $options);
$options = $this->_massageAggregateOptions($options); $options = $this->_massageAggregateOptions($options);
$cmd = array( $cmd = array(
...@@ -667,7 +690,8 @@ class Collection { ...@@ -667,7 +690,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::aggregate() options * @return array of MongoDB\Collection::aggregate() options
*/ */
function getAggregateOptions() { public function getAggregateOptions()
{
$opts = array( $opts = array(
/** /**
* Enables writing to temporary files. When set to true, aggregation stages * Enables writing to temporary files. When set to true, aggregation stages
...@@ -714,7 +738,8 @@ class Collection { ...@@ -714,7 +738,8 @@ class Collection {
* Internal helper for massaging aggregate options * Internal helper for massaging aggregate options
* @internal * @internal
*/ */
protected function _massageAggregateOptions($options) { protected function _massageAggregateOptions($options)
{
if ($options["useCursor"]) { if ($options["useCursor"]) {
$options["cursor"] = array("batchSize" => $options["batchSize"]); $options["cursor"] = array("batchSize" => $options["batchSize"]);
} }
...@@ -733,7 +758,8 @@ class Collection { ...@@ -733,7 +758,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return array The original document * @return array The original document
*/ */
function findOneAndDelete(array $filter, array $options = array()) { public function findOneAndDelete(array $filter, array $options = array())
{
$options = array_merge($this->getFindOneAndDeleteOptions(), $options); $options = array_merge($this->getFindOneAndDeleteOptions(), $options);
$options = $this->_massageFindAndModifyOptions($options); $options = $this->_massageFindAndModifyOptions($options);
$cmd = array( $cmd = array(
...@@ -754,7 +780,8 @@ class Collection { ...@@ -754,7 +780,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::findOneAndDelete() options * @return array of MongoDB\Collection::findOneAndDelete() options
*/ */
function getFindOneAndDeleteOptions() { public function getFindOneAndDeleteOptions()
{
return array( return array(
/** /**
...@@ -794,7 +821,8 @@ class Collection { ...@@ -794,7 +821,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return array * @return array
*/ */
function findOneAndReplace(array $filter, array $replacement, array $options = array()) { public function findOneAndReplace(array $filter, array $replacement, array $options = array())
{
if (key($replacement)[0] == '$') { if (key($replacement)[0] == '$') {
throw new \InvalidArgumentException("First key in \$replacement must NOT be a \$operator"); throw new \InvalidArgumentException("First key in \$replacement must NOT be a \$operator");
} }
...@@ -820,7 +848,8 @@ class Collection { ...@@ -820,7 +848,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::findOneAndReplace() options * @return array of MongoDB\Collection::findOneAndReplace() options
*/ */
function getFindOneAndReplaceOptions() { public function getFindOneAndReplaceOptions()
{
return array( return array(
/** /**
...@@ -860,7 +889,6 @@ class Collection { ...@@ -860,7 +889,6 @@ class Collection {
*/ */
"upsert" => false, "upsert" => false,
); );
} }
/** /**
...@@ -878,7 +906,8 @@ class Collection { ...@@ -878,7 +906,8 @@ class Collection {
* @param array $options Additional options * @param array $options Additional options
* @return array * @return array
*/ */
function findOneAndUpdate(array $filter, array $update, array $options = array()) { public function findOneAndUpdate(array $filter, array $update, array $options = array())
{
if (key($update)[0] != '$') { if (key($update)[0] != '$') {
throw new \InvalidArgumentException("First key in \$update must be a \$operator"); throw new \InvalidArgumentException("First key in \$update must be a \$operator");
} }
...@@ -904,7 +933,8 @@ class Collection { ...@@ -904,7 +933,8 @@ class Collection {
* *
* @return array of MongoDB\Collection::findOneAndUpdate() options * @return array of MongoDB\Collection::findOneAndUpdate() options
*/ */
function getFindOneAndUpdateOptions() { public function getFindOneAndUpdateOptions()
{
return array( return array(
/** /**
...@@ -943,14 +973,14 @@ class Collection { ...@@ -943,14 +973,14 @@ class Collection {
*/ */
"upsert" => false, "upsert" => false,
); );
} }
/** /**
* Internal helper for massaging findandmodify options * Internal helper for massaging findandmodify options
* @internal * @internal
*/ */
final protected function _massageFindAndModifyOptions($options, $update = array()) { final protected function _massageFindAndModifyOptions($options, $update = array())
{
$ret = array( $ret = array(
"sort" => $options["sort"], "sort" => $options["sort"],
"new" => isset($options["returnDocument"]) ? $options["returnDocument"] == self::FIND_ONE_AND_RETURN_AFTER : false, "new" => isset($options["returnDocument"]) ? $options["returnDocument"] == self::FIND_ONE_AND_RETURN_AFTER : false,
...@@ -970,7 +1000,8 @@ class Collection { ...@@ -970,7 +1000,8 @@ class Collection {
* Internal helper for throwing an exception with error message * Internal helper for throwing an exception with error message
* @internal * @internal
*/ */
final protected function _generateCommandException($doc) { final protected function _generateCommandException($doc)
{
if ($doc["errmsg"]) { if ($doc["errmsg"]) {
return new Exception($doc["errmsg"]); return new Exception($doc["errmsg"]);
} }
...@@ -982,7 +1013,8 @@ class Collection { ...@@ -982,7 +1013,8 @@ class Collection {
* Internal helper for running a command * Internal helper for running a command
* @internal * @internal
*/ */
final protected function _runCommand($dbname, array $cmd, ReadPreference $rp = null) { final protected function _runCommand($dbname, array $cmd, ReadPreference $rp = null)
{
//var_dump(\BSON\toJSON(\BSON\fromArray($cmd))); //var_dump(\BSON\toJSON(\BSON\fromArray($cmd)));
$command = new Command($cmd); $command = new Command($cmd);
return $this->manager->executeCommand($dbname, $command, $rp); return $this->manager->executeCommand($dbname, $command, $rp);
...@@ -993,7 +1025,8 @@ class Collection { ...@@ -993,7 +1025,8 @@ class Collection {
* *
* @return string * @return string
*/ */
function getCollectionName() { public function getCollectionName()
{
return $this->collname; return $this->collname;
} }
...@@ -1002,8 +1035,8 @@ class Collection { ...@@ -1002,8 +1035,8 @@ class Collection {
* *
* @return string * @return string
*/ */
function getDatabaseName() { public function getDatabaseName()
{
return $this->dbname; return $this->dbname;
} }
} }
<?php <?php
namespace MongoDB; namespace MongoDB;
class DeleteResult { class DeleteResult
{
protected $wr; protected $wr;
function __construct(\MongoDB\WriteResult $wr) { public function __construct(\MongoDB\WriteResult $wr)
{
$this->wr = $wr; $this->wr = $wr;
} }
function getDeletedCount() { public function getDeletedCount()
{
return $this->wr->getDeletedCount(); return $this->wr->getDeletedCount();
} }
} }
<?php <?php
namespace MongoDB; namespace MongoDB;
class InsertResult { class InsertResult
{
protected $wr; protected $wr;
function __construct(\MongoDB\WriteResult $wr, \BSON\ObjectId $id = null) { public function __construct(\MongoDB\WriteResult $wr, \BSON\ObjectId $id = null)
{
$this->wr = $wr; $this->wr = $wr;
$this->id = $id; $this->id = $id;
} }
function getInsertedId() { public function getInsertedId()
{
return $this->id; return $this->id;
} }
} }
<?php <?php
namespace MongoDB; namespace MongoDB;
class UpdateResult { class UpdateResult
{
protected $wr; protected $wr;
function __construct(\MongoDB\WriteResult $wr) { public function __construct(\MongoDB\WriteResult $wr)
{
$this->wr = $wr; $this->wr = $wr;
} }
function getMatchedCount() { public function getMatchedCount()
{
return $this->wr->getMatchedCount(); return $this->wr->getMatchedCount();
} }
function getModifiedCount() { public function getModifiedCount()
{
return $this->wr->getModifiedCount(); return $this->wr->getModifiedCount();
} }
function getUpsertedId() { public function getUpsertedId()
{
return $this->wr->getUpsertedIds()[0]; return $this->wr->getUpsertedIds()[0];
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment