Skip to content

Commit a3c0b97

Browse files
committed
Merge pull request #43
2 parents 303de40 + 4043b26 commit a3c0b97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+857
-874
lines changed

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Client
2727
* @param array $options Additional connection string options
2828
* @param array $driverOptions Driver-specific options
2929
*/
30-
public function __construct($uri, array $options = array(), array $driverOptions = array())
30+
public function __construct($uri, array $options = [], array $driverOptions = [])
3131
{
3232
$this->manager = new Manager($uri, $options, $driverOptions);
3333
}
@@ -52,7 +52,7 @@ public function dropDatabase($databaseName)
5252
* @see ListDatabases::__construct() for supported options
5353
* @return DatabaseInfoIterator
5454
*/
55-
public function listDatabases(array $options = array())
55+
public function listDatabases(array $options = [])
5656
{
5757
$operation = new ListDatabases($options);
5858
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));

src/Collection.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function __toString()
9393
* @param array $options Command options
9494
* @return Traversable
9595
*/
96-
public function aggregate(array $pipeline, array $options = array())
96+
public function aggregate(array $pipeline, array $options = [])
9797
{
9898
if ( ! isset($options['readPreference'])) {
9999
$options['readPreference'] = $this->readPreference;
@@ -117,7 +117,7 @@ public function aggregate(array $pipeline, array $options = array())
117117
* @param array $options Command options
118118
* @return BulkWriteResult
119119
*/
120-
public function bulkWrite(array $operations, array $options = array())
120+
public function bulkWrite(array $operations, array $options = [])
121121
{
122122
if ( ! isset($options['writeConcern'])) {
123123
$options['writeConcern'] = $this->writeConcern;
@@ -137,7 +137,7 @@ public function bulkWrite(array $operations, array $options = array())
137137
* @param array $options Command options
138138
* @return integer
139139
*/
140-
public function count($filter = array(), array $options = array())
140+
public function count($filter = [], array $options = [])
141141
{
142142
if ( ! isset($options['readPreference'])) {
143143
$options['readPreference'] = $this->readPreference;
@@ -158,9 +158,9 @@ public function count($filter = array(), array $options = array())
158158
* @param array $options Index options
159159
* @return string The name of the created index
160160
*/
161-
public function createIndex($key, array $options = array())
161+
public function createIndex($key, array $options = [])
162162
{
163-
return current($this->createIndexes(array(array('key' => $key) + $options)));
163+
return current($this->createIndexes([['key' => $key] + $options]));
164164
}
165165

166166
/**
@@ -203,7 +203,7 @@ public function createIndexes(array $indexes)
203203
* @param array $options Command options
204204
* @return DeleteResult
205205
*/
206-
public function deleteMany($filter, array $options = array())
206+
public function deleteMany($filter, array $options = [])
207207
{
208208
if ( ! isset($options['writeConcern'])) {
209209
$options['writeConcern'] = $this->writeConcern;
@@ -224,7 +224,7 @@ public function deleteMany($filter, array $options = array())
224224
* @param array $options Command options
225225
* @return DeleteResult
226226
*/
227-
public function deleteOne($filter, array $options = array())
227+
public function deleteOne($filter, array $options = [])
228228
{
229229
if ( ! isset($options['writeConcern'])) {
230230
$options['writeConcern'] = $this->writeConcern;
@@ -245,7 +245,7 @@ public function deleteOne($filter, array $options = array())
245245
* @param array $options Command options
246246
* @return mixed[]
247247
*/
248-
public function distinct($fieldName, $filter = array(), array $options = array())
248+
public function distinct($fieldName, $filter = [], array $options = [])
249249
{
250250
if ( ! isset($options['readPreference'])) {
251251
$options['readPreference'] = $this->readPreference;
@@ -313,7 +313,7 @@ public function dropIndexes()
313313
* @param array $options Additional options
314314
* @return Cursor
315315
*/
316-
public function find($filter = array(), array $options = array())
316+
public function find($filter = [], array $options = [])
317317
{
318318
if ( ! isset($options['readPreference'])) {
319319
$options['readPreference'] = $this->readPreference;
@@ -334,7 +334,7 @@ public function find($filter = array(), array $options = array())
334334
* @param array $options Additional options
335335
* @return object|null
336336
*/
337-
public function findOne($filter = array(), array $options = array())
337+
public function findOne($filter = [], array $options = [])
338338
{
339339
if ( ! isset($options['readPreference'])) {
340340
$options['readPreference'] = $this->readPreference;
@@ -357,7 +357,7 @@ public function findOne($filter = array(), array $options = array())
357357
* @param array $options Command options
358358
* @return object|null
359359
*/
360-
public function findOneAndDelete($filter, array $options = array())
360+
public function findOneAndDelete($filter, array $options = [])
361361
{
362362
$operation = new FindOneAndDelete($this->databaseName, $this->collectionName, $filter, $options);
363363
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
@@ -380,7 +380,7 @@ public function findOneAndDelete($filter, array $options = array())
380380
* @param array $options Command options
381381
* @return object|null
382382
*/
383-
public function findOneAndReplace($filter, $replacement, array $options = array())
383+
public function findOneAndReplace($filter, $replacement, array $options = [])
384384
{
385385
$operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options);
386386
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
@@ -403,7 +403,7 @@ public function findOneAndReplace($filter, $replacement, array $options = array(
403403
* @param array $options Command options
404404
* @return object|null
405405
*/
406-
public function findOneAndUpdate($filter, $update, array $options = array())
406+
public function findOneAndUpdate($filter, $update, array $options = [])
407407
{
408408
$operation = new FindOneAndUpdate($this->databaseName, $this->collectionName, $filter, $update, $options);
409409
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
@@ -451,7 +451,7 @@ public function getNamespace()
451451
* @param array $options Command options
452452
* @return InsertManyResult
453453
*/
454-
public function insertMany(array $documents, array $options = array())
454+
public function insertMany(array $documents, array $options = [])
455455
{
456456
if ( ! isset($options['writeConcern'])) {
457457
$options['writeConcern'] = $this->writeConcern;
@@ -472,7 +472,7 @@ public function insertMany(array $documents, array $options = array())
472472
* @param array $options Command options
473473
* @return InsertOneResult
474474
*/
475-
public function insertOne($document, array $options = array())
475+
public function insertOne($document, array $options = [])
476476
{
477477
if ( ! isset($options['writeConcern'])) {
478478
$options['writeConcern'] = $this->writeConcern;
@@ -490,7 +490,7 @@ public function insertOne($document, array $options = array())
490490
* @see ListIndexes::__construct() for supported options
491491
* @return IndexInfoIterator
492492
*/
493-
public function listIndexes(array $options = array())
493+
public function listIndexes(array $options = [])
494494
{
495495
$operation = new ListIndexes($this->databaseName, $this->collectionName, $options);
496496
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
@@ -508,7 +508,7 @@ public function listIndexes(array $options = array())
508508
* @param array $options Command options
509509
* @return UpdateResult
510510
*/
511-
public function replaceOne($filter, $replacement, array $options = array())
511+
public function replaceOne($filter, $replacement, array $options = [])
512512
{
513513
if ( ! isset($options['writeConcern'])) {
514514
$options['writeConcern'] = $this->writeConcern;
@@ -530,7 +530,7 @@ public function replaceOne($filter, $replacement, array $options = array())
530530
* @param array $options Command options
531531
* @return UpdateResult
532532
*/
533-
public function updateMany($filter, $update, array $options = array())
533+
public function updateMany($filter, $update, array $options = [])
534534
{
535535
if ( ! isset($options['writeConcern'])) {
536536
$options['writeConcern'] = $this->writeConcern;
@@ -552,7 +552,7 @@ public function updateMany($filter, $update, array $options = array())
552552
* @param array $options Command options
553553
* @return UpdateResult
554554
*/
555-
public function updateOne($filter, $update, array $options = array())
555+
public function updateOne($filter, $update, array $options = [])
556556
{
557557
if ( ! isset($options['writeConcern'])) {
558558
$options['writeConcern'] = $this->writeConcern;

src/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __toString()
6666
* @param array $options
6767
* @return object Command result document
6868
*/
69-
public function createCollection($collectionName, array $options = array())
69+
public function createCollection($collectionName, array $options = [])
7070
{
7171
$operation = new CreateCollection($this->databaseName, $collectionName, $options);
7272
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
@@ -118,7 +118,7 @@ public function getDatabaseName()
118118
* @param array $options
119119
* @return CollectionInfoIterator
120120
*/
121-
public function listCollections(array $options = array())
121+
public function listCollections(array $options = [])
122122
{
123123
$operation = new ListCollections($this->databaseName, $options);
124124
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));

src/Model/CollectionInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function getName()
7575
*/
7676
public function getOptions()
7777
{
78-
return isset($this->info['options']) ? (array) $this->info['options'] : array();
78+
return isset($this->info['options']) ? (array) $this->info['options'] : [];
7979
}
8080

8181
/**

src/Operation/Aggregate.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Aggregate implements Executable
6060
* @param array $options Command options
6161
* @throws InvalidArgumentException
6262
*/
63-
public function __construct($databaseName, $collectionName, array $pipeline, array $options = array())
63+
public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
6464
{
6565
if (empty($pipeline)) {
6666
throw new InvalidArgumentException('$pipeline is empty');
@@ -80,10 +80,10 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
8080
$expectedIndex += 1;
8181
}
8282

83-
$options += array(
83+
$options += [
8484
'allowDiskUse' => false,
8585
'useCursor' => true,
86-
);
86+
];
8787

8888
if ( ! is_bool($options['allowDiskUse'])) {
8989
throw new InvalidArgumentTypeException('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
@@ -156,10 +156,10 @@ public function execute(Server $server)
156156
*/
157157
private function createCommand(Server $server, $isCursorSupported)
158158
{
159-
$cmd = array(
159+
$cmd = [
160160
'aggregate' => $this->collectionName,
161161
'pipeline' => $this->pipeline,
162-
);
162+
];
163163

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

175175
if ($this->options['useCursor']) {
176176
$cmd['cursor'] = isset($this->options["batchSize"])
177-
? array('batchSize' => $this->options["batchSize"])
177+
? ['batchSize' => $this->options["batchSize"]]
178178
: new stdClass;
179179
}
180180

src/Operation/BulkWrite.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BulkWrite implements Executable
6666
* @param array $options Command options
6767
* @throws InvalidArgumentException
6868
*/
69-
public function __construct($databaseName, $collectionName, array $operations, array $options = array())
69+
public function __construct($databaseName, $collectionName, array $operations, array $options = [])
7070
{
7171
if (empty($operations)) {
7272
throw new InvalidArgumentException('$operations is empty');
@@ -104,7 +104,7 @@ public function __construct($databaseName, $collectionName, array $operations, a
104104

105105
case self::DELETE_MANY:
106106
case self::DELETE_ONE:
107-
$operations[$i][$type][1] = array('limit' => ($type === self::DELETE_ONE ? 1 : 0));
107+
$operations[$i][$type][1] = ['limit' => ($type === self::DELETE_ONE ? 1 : 0)];
108108

109109
break;
110110

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

124124
if ( ! isset($args[2])) {
125-
$args[2] = array();
125+
$args[2] = [];
126126
}
127127

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

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

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

157157
if ( ! isset($args[2])) {
158-
$args[2] = array();
158+
$args[2] = [];
159159
}
160160

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

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

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

183-
$options += array(
184-
'ordered' => true,
185-
);
183+
$options += ['ordered' => true];
186184

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

213211
foreach ($this->operations as $i => $operation) {
214212
$type = key($operation);

src/Operation/Count.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Count implements Executable
4848
* @param array $options Command options
4949
* @throws InvalidArgumentException
5050
*/
51-
public function __construct($databaseName, $collectionName, $filter = array(), array $options = array())
51+
public function __construct($databaseName, $collectionName, $filter = [], array $options = [])
5252
{
5353
if ( ! is_array($filter) && ! is_object($filter)) {
5454
throw new InvalidArgumentTypeException('$filter', $filter, 'array or object');
@@ -119,15 +119,13 @@ public function execute(Server $server)
119119
*/
120120
private function createCommand()
121121
{
122-
$cmd = array(
123-
'count' => $this->collectionName,
124-
);
122+
$cmd = ['count' => $this->collectionName];
125123

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

130-
foreach (array('hint', 'limit', 'maxTimeMS', 'skip') as $option) {
128+
foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
131129
if (isset($this->options[$option])) {
132130
$cmd[$option] = $this->options[$option];
133131
}

src/Operation/CreateCollection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CreateCollection implements Executable
2323

2424
private $databaseName;
2525
private $collectionName;
26-
private $options = array();
26+
private $options = [];
2727

2828
/**
2929
* Constructs a create command.
@@ -57,7 +57,7 @@ class CreateCollection implements Executable
5757
* @param array $options Command options
5858
* @throws InvalidArgumentException
5959
*/
60-
public function __construct($databaseName, $collectionName, array $options = array())
60+
public function __construct($databaseName, $collectionName, array $options = [])
6161
{
6262
if (isset($options['autoIndexId']) && ! is_bool($options['autoIndexId'])) {
6363
throw new InvalidArgumentTypeException('"autoIndexId" option', $options['autoIndexId'], 'boolean');
@@ -118,9 +118,9 @@ public function execute(Server $server)
118118
*/
119119
private function createCommand()
120120
{
121-
$cmd = array('create' => $this->collectionName);
121+
$cmd = ['create' => $this->collectionName];
122122

123-
foreach (array('autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size') as $option) {
123+
foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size'] as $option) {
124124
if (isset($this->options[$option])) {
125125
$cmd[$option] = $this->options[$option];
126126
}

0 commit comments

Comments
 (0)