Skip to content

Commit

Permalink
Use short array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed Feb 17, 2015
1 parent 5ed6ca6 commit 5e45db6
Show file tree
Hide file tree
Showing 26 changed files with 1,241 additions and 1,241 deletions.
2 changes: 1 addition & 1 deletion phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
include './vendor/autoload.php';

// Remove when fix is merged.
Mockery::getConfiguration()->setInternalClassMethodParamMap('MongoCollection', "aggregate", array('$pipeline', '$op = NULL', '$third = NULL'));
Mockery::getConfiguration()->setInternalClassMethodParamMap('MongoCollection', "aggregate", ['$pipeline', '$op = NULL', '$third = NULL']);
4 changes: 2 additions & 2 deletions src/League/Monga.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function id($id)
*
* @return object MongoCode
*/
public static function code($code, $scope = array())
public static function code($code, $scope = [])
{
return new MongoCode($code, $scope);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public static function regex($regex)
*
* @return object Monga\Connection
*/
public static function connection($server = null, array $options = array())
public static function connection($server = null, array $options = [])
{
return new Connection($server, $options);
}
Expand Down
42 changes: 21 additions & 21 deletions src/League/Monga/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function drop()
*
* @return int number of documents
*/
public function count($query = array())
public function count($query = [])
{
if ($query instanceof Closure) {
$callback = $query;
Expand All @@ -122,7 +122,7 @@ public function count($query = array())
*
* @return array array of distinct values
*/
public function distinct($key, $query = array())
public function distinct($key, $query = [])
{
if ($query instanceof Closure) {
// Store the callback
Expand Down Expand Up @@ -150,7 +150,7 @@ public function distinct($key, $query = array())
*
* @return array aggregation result
*/
public function aggregate($aggregation = array())
public function aggregate($aggregation = [])
{
if ($aggregation instanceof Closure) {
// Store the callback
Expand Down Expand Up @@ -179,7 +179,7 @@ public function aggregate($aggregation = array())
*/
public function truncate()
{
$result = $this->collection->remove(array());
$result = $this->collection->remove([]);

return $result === true || (bool) $result['ok'];
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public function listIndexes()
*
* @return mixed false on failure, number of deleted items on success
*/
public function remove($criteria, $options = array())
public function remove($criteria, $options = [])
{
if ($criteria instanceof Closure) {
// Create new Remove query
Expand Down Expand Up @@ -252,7 +252,7 @@ public function remove($criteria, $options = array())
// Retry "save" in case of rediscovery latency issues
// in replica set failover. Error codes 10107, 13435, and 10058
// are MongoCursorException's "not master" errors.
if (in_array($e->getCode(), array(10107, 13435, 10058))) {
if (in_array($e->getCode(), [10107, 13435, 10058])) {
if ($tries === $maxRetries) {
throw $e;
} else {
Expand All @@ -277,7 +277,7 @@ public function remove($criteria, $options = array())
*
* @return mixed result Cursor for multiple, document array for one.
*/
public function find($query = array(), $fields = array(), $findOne = false)
public function find($query = [], $fields = [], $findOne = false)
{
$postFind = false;

Expand All @@ -300,15 +300,15 @@ public function find($query = array(), $fields = array(), $findOne = false)
}

// Prepare the find arguments
$arguments = array();
$arguments = [];
empty($query) || $arguments[] = $query;
empty($fields) || $arguments[] = $fields;

// Wrap the find function so it is callable
$function = array(
$function = [
$this->getCollection(),
($findOne && ! $postFind) ? 'findOne' : 'find',
);
];

$result = call_user_func_array($function, $arguments);

Expand All @@ -317,7 +317,7 @@ public function find($query = array(), $fields = array(), $findOne = false)
foreach ($postFind as $arguments) {
$method = array_shift($arguments);

$result = call_user_func_array(array($result, $method), $arguments);
$result = call_user_func_array([$result, $method], $arguments);
}
}

Expand All @@ -339,7 +339,7 @@ public function find($query = array(), $fields = array(), $findOne = false)
*
* @return array|null document array when found, null when not found
*/
public function findOne($query = array(), $fields = array())
public function findOne($query = [], $fields = [])
{
return $this->find($query, $fields, true);
}
Expand All @@ -352,7 +352,7 @@ public function findOne($query = array(), $fields = array())
*
* @return boolean success boolean
*/
public function insert(array $data, $options = array())
public function insert(array $data, $options = [])
{
$maxRetries = $this->maxRetries;
$tries = 0;
Expand All @@ -368,7 +368,7 @@ public function insert(array $data, $options = array())
// Retry "save" in case of rediscovery latency issues
// in replica set failover. Error codes 10107, 13435, and 10058
// are MongoCursorException's "not master" errors.
if (in_array($e->getCode(), array(10107, 13435, 10058))) {
if (in_array($e->getCode(), [10107, 13435, 10058])) {
if ($tries === $maxRetries) {
throw $e;
} else {
Expand All @@ -385,7 +385,7 @@ public function insert(array $data, $options = array())
return false;
}

$result = array();
$result = [];

foreach ($data as $r) {
// Collect all the id's for the return value
Expand All @@ -404,7 +404,7 @@ public function insert(array $data, $options = array())
// Retry "save" in case of rediscovery latency issues
// in replica set failover. Error codes 10107, 13435, and 10058
// are MongoCursorException's "not master" errors.
if (in_array($e->getCode(), array(10107, 13435, 10058))) {
if (in_array($e->getCode(), [10107, 13435, 10058])) {
if ($tries === $maxRetries) {
throw $e;
} else {
Expand Down Expand Up @@ -433,7 +433,7 @@ public function insert(array $data, $options = array())
*
* @return boolean query success
*/
public function update($values = array(), $query = null, $options = array())
public function update($values = [], $query = null, $options = [])
{
if ($values instanceof Closure) {
$query = new Query\Update();
Expand All @@ -449,7 +449,7 @@ public function update($values = array(), $query = null, $options = array())
throw new \InvalidArgumentException('Update params $update and $options must be arrays.');
}

isset($query) || $query = array();
isset($query) || $query = [];

$maxRetries = $this->maxRetries;
$tries = 0;
Expand All @@ -462,7 +462,7 @@ public function update($values = array(), $query = null, $options = array())
// Retry "save" in case of rediscovery latency issues
// in replica set failover. Error codes 10107, 13435, and 10058
// are MongoCursorException's "not master" errors.
if (in_array($e->getCode(), array(10107, 13435, 10058))) {
if (in_array($e->getCode(), [10107, 13435, 10058])) {
if ($tries === $maxRetries) {
throw $e;
} else {
Expand All @@ -486,7 +486,7 @@ public function update($values = array(), $query = null, $options = array())
*
* @return boolean success boolean
*/
public function save(&$document, $options = array())
public function save(&$document, $options = [])
{
$maxRetries = $this->maxRetries;
$tries = 0;
Expand All @@ -499,7 +499,7 @@ public function save(&$document, $options = array())
// Retry "save" in case of rediscovery latency issues
// in replica set failover. Error codes 10107, 13435, and 10058
// are MongoCursorException's "not master" errors.
if (in_array($e->getCode(), array(10107, 13435, 10058))) {
if (in_array($e->getCode(), [10107, 13435, 10058])) {
if ($tries === $maxRetries) {
throw $e;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/League/Monga/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Connection
* @param string $server mongo dns
* @param array $options connection options
*/
public function __construct($server = null, array $options = array())
public function __construct($server = null, array $options = [])
{
if ($server instanceof MongoClient) {
$this->connection = $server;
Expand Down Expand Up @@ -126,7 +126,7 @@ public function isConnected()
*/
public function dropDatabase($database)
{
$result = $this->connection->{$database}->command(array('dropDatabase' => 1));
$result = $this->connection->{$database}->command(['dropDatabase' => 1]);

return (bool) $result['ok'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/League/Monga/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __call($method, $arguments)
}

// Trigger the method.
$function = array($this->result, $method);
$function = [$this->result, $method];
$result = call_user_func_array($function, $arguments);

// When the cursor is returned, return the current instance.
Expand Down
6 changes: 3 additions & 3 deletions src/League/Monga/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function drop()
public function getRef($reference)
{
$array = ! isset($reference['$ref']);
$reference = $array ? $reference : array($reference);
$reference = $array ? $reference : [$reference];
$database = $this->database;

$result = array_map(
Expand All @@ -212,7 +212,7 @@ function ($ref) use ($database) {
*
* @return mixed result
*/
public function executeCode($code, array $arguments = array())
public function executeCode($code, array $arguments = [])
{
if (! ($code instanceof MongoCode)) {
$code = new MongoCode($code);
Expand All @@ -228,7 +228,7 @@ public function executeCode($code, array $arguments = array())
* @param array $options command options
* @param array result
*/
public function command(array $command, array $options = array())
public function command(array $command, array $options = [])
{
return $this->database->command($command, $options);
}
Expand Down
14 changes: 7 additions & 7 deletions src/League/Monga/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(MongoGridFS $filesystem)
*
* @return object MongoId object
*/
public function store($filename, $metadata = array())
public function store($filename, $metadata = [])
{
return $this->collection->put($filename, $metadata);
}
Expand All @@ -53,7 +53,7 @@ public function store($filename, $metadata = array())
*
* @return object MongoId object
*/
public function storeBytes($bytes, $metadata = array(), $options = array())
public function storeBytes($bytes, $metadata = [], $options = [])
{
return $this->collection->storeBytes($bytes, $metadata, $options);
}
Expand All @@ -67,7 +67,7 @@ public function storeBytes($bytes, $metadata = array(), $options = array())
*
* @return object MongoId object
*/
public function storeFile($filename, $metadata = array(), $options = array())
public function storeFile($filename, $metadata = [], $options = [])
{
return $this->collection->storeFile($filename, $metadata, $options);
}
Expand All @@ -80,7 +80,7 @@ public function storeFile($filename, $metadata = array(), $options = array())
*
* @return object MongoId object
*/
public function storeUpload($name, $metadata = array())
public function storeUpload($name, $metadata = [])
{
return $this->collection->storeUpload($name, $metadata);
}
Expand All @@ -103,7 +103,7 @@ public function extract($name, $destination = null)
return false;
}

return (bool) $this->collection->remove(array('_id' => $file->file['_id']));
return (bool) $this->collection->remove(['_id' => $file->file['_id']]);
}

/**
Expand All @@ -114,10 +114,10 @@ public function extract($name, $destination = null)
*
* @return object|null MongoGridFSFile instance or null when not found.
*/
public function findOne($query = array(), $fields = array())
public function findOne($query = [], $fields = [])
{
if (is_string($query)) {
return $this->collection->findOne($query, $fields = array());
return $this->collection->findOne($query, $fields = []);
}

return parent::findOne($query, $fields);
Expand Down
14 changes: 7 additions & 7 deletions src/League/Monga/Query/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Aggregation
/**
* @var array $pipeline aggregation pipeline
*/
protected $pipeline = array();
protected $pipeline = [];

/**
* Project the results.
Expand All @@ -40,7 +40,7 @@ public function project($projection)
$projection = $projection->getProjection();
}

$this->pipeline[] = array('$project' => $projection);
$this->pipeline[] = ['$project' => $projection];

return $this;
}
Expand All @@ -65,7 +65,7 @@ public function group($group)
$group = $group->getGroup();
}

$this->pipeline[] = array('$group' => $group);
$this->pipeline[] = ['$group' => $group];

return $this;
}
Expand All @@ -79,7 +79,7 @@ public function group($group)
*/
public function unwind($field)
{
$this->pipeline[] = array('$unwind' => '$'.ltrim($field, '$'));
$this->pipeline[] = ['$unwind' => '$'.ltrim($field, '$')];

return $this;
}
Expand All @@ -93,7 +93,7 @@ public function unwind($field)
*/
public function skip($amount)
{
$this->pipeline[] = array('$skip' => (int) $amount);
$this->pipeline[] = ['$skip' => (int) $amount];

return $this;
}
Expand All @@ -107,7 +107,7 @@ public function skip($amount)
*/
public function limit($amount)
{
$this->pipeline[] = array('$limit' => (int) $amount);
$this->pipeline[] = ['$limit' => (int) $amount];

return $this;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public function match($filter)
$filter = $filter->getWhere();
}

$this->pipeline[] = array('$match' => $filter);
$this->pipeline[] = ['$match' => $filter];

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/League/Monga/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public function fsync($fsync = true)
*/
public function getOptions()
{
return array(
return [
'w' => $this->safe ? 1 : 0,
'fsync' => $this->fsync,
'connectTimeoutMS' => $this->timeout ?: MongoCursor::$timeout,
);
];
}

/**
Expand Down
Loading

0 comments on commit 5e45db6

Please sign in to comment.