Skip to content

Shorthand array syntax #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Client
* @param array $options Additional connection string options
* @param array $driverOptions Driver-specific options
*/
public function __construct($uri, array $options = array(), array $driverOptions = array())
public function __construct($uri, array $options = [], array $driverOptions = [])
{
$this->manager = new Manager($uri, $options, $driverOptions);
}
Expand All @@ -52,7 +52,7 @@ public function dropDatabase($databaseName)
* @see ListDatabases::__construct() for supported options
* @return DatabaseInfoIterator
*/
public function listDatabases(array $options = array())
public function listDatabases(array $options = [])
{
$operation = new ListDatabases($options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand Down
38 changes: 19 additions & 19 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __toString()
* @param array $options Command options
* @return Traversable
*/
public function aggregate(array $pipeline, array $options = array())
public function aggregate(array $pipeline, array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
Expand All @@ -117,7 +117,7 @@ public function aggregate(array $pipeline, array $options = array())
* @param array $options Command options
* @return BulkWriteResult
*/
public function bulkWrite(array $operations, array $options = array())
public function bulkWrite(array $operations, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -137,7 +137,7 @@ public function bulkWrite(array $operations, array $options = array())
* @param array $options Command options
* @return integer
*/
public function count($filter = array(), array $options = array())
public function count($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
Expand All @@ -158,9 +158,9 @@ public function count($filter = array(), array $options = array())
* @param array $options Index options
* @return string The name of the created index
*/
public function createIndex($key, array $options = array())
public function createIndex($key, array $options = [])
{
return current($this->createIndexes(array(array('key' => $key) + $options)));
return current($this->createIndexes([['key' => $key] + $options]));
}

/**
Expand Down Expand Up @@ -203,7 +203,7 @@ public function createIndexes(array $indexes)
* @param array $options Command options
* @return DeleteResult
*/
public function deleteMany($filter, array $options = array())
public function deleteMany($filter, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -224,7 +224,7 @@ public function deleteMany($filter, array $options = array())
* @param array $options Command options
* @return DeleteResult
*/
public function deleteOne($filter, array $options = array())
public function deleteOne($filter, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -245,7 +245,7 @@ public function deleteOne($filter, array $options = array())
* @param array $options Command options
* @return mixed[]
*/
public function distinct($fieldName, $filter = array(), array $options = array())
public function distinct($fieldName, $filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
Expand Down Expand Up @@ -313,7 +313,7 @@ public function dropIndexes()
* @param array $options Additional options
* @return Cursor
*/
public function find($filter = array(), array $options = array())
public function find($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
Expand All @@ -334,7 +334,7 @@ public function find($filter = array(), array $options = array())
* @param array $options Additional options
* @return object|null
*/
public function findOne($filter = array(), array $options = array())
public function findOne($filter = [], array $options = [])
{
if ( ! isset($options['readPreference'])) {
$options['readPreference'] = $this->readPreference;
Expand All @@ -357,7 +357,7 @@ public function findOne($filter = array(), array $options = array())
* @param array $options Command options
* @return object|null
*/
public function findOneAndDelete($filter, array $options = array())
public function findOneAndDelete($filter, array $options = [])
{
$operation = new FindOneAndDelete($this->databaseName, $this->collectionName, $filter, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand All @@ -380,7 +380,7 @@ public function findOneAndDelete($filter, array $options = array())
* @param array $options Command options
* @return object|null
*/
public function findOneAndReplace($filter, $replacement, array $options = array())
public function findOneAndReplace($filter, $replacement, array $options = [])
{
$operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand All @@ -403,7 +403,7 @@ public function findOneAndReplace($filter, $replacement, array $options = array(
* @param array $options Command options
* @return object|null
*/
public function findOneAndUpdate($filter, $update, array $options = array())
public function findOneAndUpdate($filter, $update, array $options = [])
{
$operation = new FindOneAndUpdate($this->databaseName, $this->collectionName, $filter, $update, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand Down Expand Up @@ -451,7 +451,7 @@ public function getNamespace()
* @param array $options Command options
* @return InsertManyResult
*/
public function insertMany(array $documents, array $options = array())
public function insertMany(array $documents, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -472,7 +472,7 @@ public function insertMany(array $documents, array $options = array())
* @param array $options Command options
* @return InsertOneResult
*/
public function insertOne($document, array $options = array())
public function insertOne($document, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -490,7 +490,7 @@ public function insertOne($document, array $options = array())
* @see ListIndexes::__construct() for supported options
* @return IndexInfoIterator
*/
public function listIndexes(array $options = array())
public function listIndexes(array $options = [])
{
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand All @@ -508,7 +508,7 @@ public function listIndexes(array $options = array())
* @param array $options Command options
* @return UpdateResult
*/
public function replaceOne($filter, $replacement, array $options = array())
public function replaceOne($filter, $replacement, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -530,7 +530,7 @@ public function replaceOne($filter, $replacement, array $options = array())
* @param array $options Command options
* @return UpdateResult
*/
public function updateMany($filter, $update, array $options = array())
public function updateMany($filter, $update, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand All @@ -552,7 +552,7 @@ public function updateMany($filter, $update, array $options = array())
* @param array $options Command options
* @return UpdateResult
*/
public function updateOne($filter, $update, array $options = array())
public function updateOne($filter, $update, array $options = [])
{
if ( ! isset($options['writeConcern'])) {
$options['writeConcern'] = $this->writeConcern;
Expand Down
4 changes: 2 additions & 2 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __toString()
* @param array $options
* @return object Command result document
*/
public function createCollection($collectionName, array $options = array())
public function createCollection($collectionName, array $options = [])
{
$operation = new CreateCollection($this->databaseName, $collectionName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand Down Expand Up @@ -118,7 +118,7 @@ public function getDatabaseName()
* @param array $options
* @return CollectionInfoIterator
*/
public function listCollections(array $options = array())
public function listCollections(array $options = [])
{
$operation = new ListCollections($this->databaseName, $options);
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
Expand Down
2 changes: 1 addition & 1 deletion src/Model/CollectionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getName()
*/
public function getOptions()
{
return isset($this->info['options']) ? (array) $this->info['options'] : array();
return isset($this->info['options']) ? (array) $this->info['options'] : [];
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Aggregate implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $pipeline, array $options = array())
public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
{
if (empty($pipeline)) {
throw new InvalidArgumentException('$pipeline is empty');
Expand All @@ -80,10 +80,10 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
$expectedIndex += 1;
}

$options += array(
$options += [
'allowDiskUse' => false,
'useCursor' => true,
);
];

if ( ! is_bool($options['allowDiskUse'])) {
throw new InvalidArgumentTypeException('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
Expand Down Expand Up @@ -156,10 +156,10 @@ public function execute(Server $server)
*/
private function createCommand(Server $server, $isCursorSupported)
{
$cmd = array(
$cmd = [
'aggregate' => $this->collectionName,
'pipeline' => $this->pipeline,
);
];

// Servers < 2.6 do not support any command options
if ( ! $isCursorSupported) {
Expand All @@ -174,7 +174,7 @@ private function createCommand(Server $server, $isCursorSupported)

if ($this->options['useCursor']) {
$cmd['cursor'] = isset($this->options["batchSize"])
? array('batchSize' => $this->options["batchSize"])
? ['batchSize' => $this->options["batchSize"]]
: new stdClass;
}

Expand Down
18 changes: 8 additions & 10 deletions src/Operation/BulkWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BulkWrite implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $operations, array $options = array())
public function __construct($databaseName, $collectionName, array $operations, array $options = [])
{
if (empty($operations)) {
throw new InvalidArgumentException('$operations is empty');
Expand Down Expand Up @@ -104,7 +104,7 @@ public function __construct($databaseName, $collectionName, array $operations, a

case self::DELETE_MANY:
case self::DELETE_ONE:
$operations[$i][$type][1] = array('limit' => ($type === self::DELETE_ONE ? 1 : 0));
$operations[$i][$type][1] = ['limit' => ($type === self::DELETE_ONE ? 1 : 0)];

break;

Expand All @@ -122,15 +122,15 @@ public function __construct($databaseName, $collectionName, array $operations, a
}

if ( ! isset($args[2])) {
$args[2] = array();
$args[2] = [];
}

if ( ! is_array($args[2])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
}

$args[2]['multi'] = false;
$args[2] += array('upsert' => false);
$args[2] += ['upsert' => false];

if ( ! is_bool($args[2]['upsert'])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
Expand All @@ -155,15 +155,15 @@ public function __construct($databaseName, $collectionName, array $operations, a
}

if ( ! isset($args[2])) {
$args[2] = array();
$args[2] = [];
}

if ( ! is_array($args[2])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]', $i, $type), $args[2], 'array');
}

$args[2]['multi'] = ($type === self::UPDATE_MANY);
$args[2] += array('upsert' => false);
$args[2] += ['upsert' => false];

if ( ! is_bool($args[2]['upsert'])) {
throw new InvalidArgumentTypeException(sprintf('$operations[%d]["%s"][2]["upsert"]', $i, $type), $args[2]['upsert'], 'boolean');
Expand All @@ -180,9 +180,7 @@ public function __construct($databaseName, $collectionName, array $operations, a
$expectedIndex += 1;
}

$options += array(
'ordered' => true,
);
$options += ['ordered' => true];

if ( ! is_bool($options['ordered'])) {
throw new InvalidArgumentTypeException('"ordered" option', $options['ordered'], 'boolean');
Expand All @@ -208,7 +206,7 @@ public function __construct($databaseName, $collectionName, array $operations, a
public function execute(Server $server)
{
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = array();
$insertedIds = [];

foreach ($this->operations as $i => $operation) {
$type = key($operation);
Expand Down
8 changes: 3 additions & 5 deletions src/Operation/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Count implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter = array(), array $options = array())
public function __construct($databaseName, $collectionName, $filter = [], array $options = [])
{
if ( ! is_array($filter) && ! is_object($filter)) {
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
Expand Down Expand Up @@ -119,15 +119,13 @@ public function execute(Server $server)
*/
private function createCommand()
{
$cmd = array(
'count' => $this->collectionName,
);
$cmd = ['count' => $this->collectionName];

if ( ! empty($this->filter)) {
$cmd['query'] = (object) $this->filter;
}

foreach (array('hint', 'limit', 'maxTimeMS', 'skip') as $option) {
foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
Expand Down
8 changes: 4 additions & 4 deletions src/Operation/CreateCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CreateCollection implements Executable

private $databaseName;
private $collectionName;
private $options = array();
private $options = [];

/**
* Constructs a create command.
Expand Down Expand Up @@ -57,7 +57,7 @@ class CreateCollection implements Executable
* @param array $options Command options
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, array $options = array())
public function __construct($databaseName, $collectionName, array $options = [])
{
if (isset($options['autoIndexId']) && ! is_bool($options['autoIndexId'])) {
throw new InvalidArgumentTypeException('"autoIndexId" option', $options['autoIndexId'], 'boolean');
Expand Down Expand Up @@ -118,9 +118,9 @@ public function execute(Server $server)
*/
private function createCommand()
{
$cmd = array('create' => $this->collectionName);
$cmd = ['create' => $this->collectionName];

foreach (array('autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size') as $option) {
foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
Expand Down
Loading