Commit fb239b53 authored by pi0's avatar pi0

Reformat

parent 624b294c
...@@ -69,12 +69,12 @@ class Builder extends BaseBuilder ...@@ -69,12 +69,12 @@ class Builder extends BaseBuilder
* @var array * @var array
*/ */
protected $conversion = [ protected $conversion = [
'=' => '=', '=' => '=',
'!=' => '$ne', '!=' => '$ne',
'<>' => '$ne', '<>' => '$ne',
'<' => '$lt', '<' => '$lt',
'<=' => '$lte', '<=' => '$lte',
'>' => '$gt', '>' => '$gt',
'>=' => '$gte', '>=' => '$gte',
]; ];
...@@ -84,12 +84,12 @@ class Builder extends BaseBuilder ...@@ -84,12 +84,12 @@ class Builder extends BaseBuilder
* @var boolean * @var boolean
*/ */
protected $use_collection; protected $use_collection;
/** /**
* Create a new query builder instance. * Create a new query builder instance.
* *
* @param Connection $connection * @param Connection $connection
* @param Processor $processor * @param Processor $processor
*/ */
public function __construct(Connection $connection, Processor $processor) public function __construct(Connection $connection, Processor $processor)
{ {
...@@ -103,7 +103,7 @@ class Builder extends BaseBuilder ...@@ -103,7 +103,7 @@ class Builder extends BaseBuilder
/** /**
* Set the projections. * Set the projections.
* *
* @param array $columns * @param array $columns
* @return $this * @return $this
*/ */
public function project($columns) public function project($columns)
...@@ -142,8 +142,8 @@ class Builder extends BaseBuilder ...@@ -142,8 +142,8 @@ class Builder extends BaseBuilder
/** /**
* Execute a query for a single record by ID. * Execute a query for a single record by ID.
* *
* @param mixed $id * @param mixed $id
* @param array $columns * @param array $columns
* @return mixed * @return mixed
*/ */
public function find($id, $columns = []) public function find($id, $columns = [])
...@@ -154,7 +154,7 @@ class Builder extends BaseBuilder ...@@ -154,7 +154,7 @@ class Builder extends BaseBuilder
/** /**
* Execute the query as a "select" statement. * Execute the query as a "select" statement.
* *
* @param array $columns * @param array $columns
* @return array|static[]|Collection * @return array|static[]|Collection
*/ */
public function get($columns = []) public function get($columns = [])
...@@ -165,7 +165,7 @@ class Builder extends BaseBuilder ...@@ -165,7 +165,7 @@ class Builder extends BaseBuilder
/** /**
* Execute the query as a fresh "select" statement. * Execute the query as a fresh "select" statement.
* *
* @param array $columns * @param array $columns
* @return array|static[]|Collection * @return array|static[]|Collection
*/ */
public function getFresh($columns = []) public function getFresh($columns = [])
...@@ -216,7 +216,8 @@ class Builder extends BaseBuilder ...@@ -216,7 +216,8 @@ class Builder extends BaseBuilder
// Translate count into sum. // Translate count into sum.
if ($function == 'count') { if ($function == 'count') {
$group['aggregate'] = ['$sum' => 1]; $group['aggregate'] = ['$sum' => 1];
} // Pass other functions directly. }
// Pass other functions directly.
else { else {
$group['aggregate'] = ['$' . $function => '$' . $column]; $group['aggregate'] = ['$' . $function => '$' . $column];
} }
...@@ -267,8 +268,10 @@ class Builder extends BaseBuilder ...@@ -267,8 +268,10 @@ class Builder extends BaseBuilder
$results = iterator_to_array($this->collection->aggregate($pipeline, $options)); $results = iterator_to_array($this->collection->aggregate($pipeline, $options));
// Return results // Return results
return $this->use_collection ? new Collection($results) : $results; return SHOULD_RETURN_COLLECTION ? new Collection($results) : $results;
} // Distinct query }
// Distinct query
elseif ($this->distinct) { elseif ($this->distinct) {
// Return distinct results directly // Return distinct results directly
$column = isset($this->columns[0]) ? $this->columns[0] : '_id'; $column = isset($this->columns[0]) ? $this->columns[0] : '_id';
...@@ -280,8 +283,10 @@ class Builder extends BaseBuilder ...@@ -280,8 +283,10 @@ class Builder extends BaseBuilder
$result = $this->collection->distinct($column); $result = $this->collection->distinct($column);
} }
return $this->use_collection ? new Collection($result) : $result; return SHOULD_RETURN_COLLECTION ? new Collection($result) : $result;
} // Normal query }
// Normal query
else { else {
$columns = []; $columns = [];
...@@ -322,7 +327,7 @@ class Builder extends BaseBuilder ...@@ -322,7 +327,7 @@ class Builder extends BaseBuilder
// Return results as an array with numeric keys // Return results as an array with numeric keys
$results = iterator_to_array($cursor, false); $results = iterator_to_array($cursor, false);
return $this->use_collection ? new Collection($results) : $results; return SHOULD_RETURN_COLLECTION ? new Collection($results) : $results;
} }
} }
...@@ -336,13 +341,13 @@ class Builder extends BaseBuilder ...@@ -336,13 +341,13 @@ class Builder extends BaseBuilder
$key = [ $key = [
'connection' => $this->collection->getDatabaseName(), 'connection' => $this->collection->getDatabaseName(),
'collection' => $this->collection->getCollectionName(), 'collection' => $this->collection->getCollectionName(),
'wheres' => $this->wheres, 'wheres' => $this->wheres,
'columns' => $this->columns, 'columns' => $this->columns,
'groups' => $this->groups, 'groups' => $this->groups,
'orders' => $this->orders, 'orders' => $this->orders,
'offset' => $this->offset, 'offset' => $this->offset,
'limit' => $this->limit, 'limit' => $this->limit,
'aggregate' => $this->aggregate, 'aggregate' => $this->aggregate,
]; ];
return md5(serialize(array_values($key))); return md5(serialize(array_values($key)));
...@@ -351,8 +356,8 @@ class Builder extends BaseBuilder ...@@ -351,8 +356,8 @@ class Builder extends BaseBuilder
/** /**
* Execute an aggregate function on the database. * Execute an aggregate function on the database.
* *
* @param string $function * @param string $function
* @param array $columns * @param array $columns
* @return mixed * @return mixed
*/ */
public function aggregate($function, $columns = []) public function aggregate($function, $columns = [])
...@@ -368,7 +373,7 @@ class Builder extends BaseBuilder ...@@ -368,7 +373,7 @@ class Builder extends BaseBuilder
$this->aggregate = null; $this->aggregate = null;
if (isset($results[0])) { if (isset($results[0])) {
$result = (array)$results[0]; $result = (array) $results[0];
return $result['aggregate']; return $result['aggregate'];
} }
...@@ -381,7 +386,7 @@ class Builder extends BaseBuilder ...@@ -381,7 +386,7 @@ class Builder extends BaseBuilder
*/ */
public function exists() public function exists()
{ {
return !is_null($this->first()); return ! is_null($this->first());
} }
/** /**
...@@ -403,8 +408,8 @@ class Builder extends BaseBuilder ...@@ -403,8 +408,8 @@ class Builder extends BaseBuilder
/** /**
* Add an "order by" clause to the query. * Add an "order by" clause to the query.
* *
* @param string $column * @param string $column
* @param string $direction * @param string $direction
* @return Builder * @return Builder
*/ */
public function orderBy($column, $direction = 'asc') public function orderBy($column, $direction = 'asc')
...@@ -425,10 +430,10 @@ class Builder extends BaseBuilder ...@@ -425,10 +430,10 @@ class Builder extends BaseBuilder
/** /**
* Add a where between statement to the query. * Add a where between statement to the query.
* *
* @param string $column * @param string $column
* @param array $values * @param array $values
* @param string $boolean * @param string $boolean
* @param bool $not * @param bool $not
* @return Builder * @return Builder
*/ */
public function whereBetween($column, array $values, $boolean = 'and', $not = false) public function whereBetween($column, array $values, $boolean = 'and', $not = false)
...@@ -443,8 +448,8 @@ class Builder extends BaseBuilder ...@@ -443,8 +448,8 @@ class Builder extends BaseBuilder
/** /**
* Set the limit and offset for a given page. * Set the limit and offset for a given page.
* *
* @param int $page * @param int $page
* @param int $perPage * @param int $perPage
* @return \Illuminate\Database\Query\Builder|static * @return \Illuminate\Database\Query\Builder|static
*/ */
public function forPage($page, $perPage = 15) public function forPage($page, $perPage = 15)
...@@ -457,7 +462,7 @@ class Builder extends BaseBuilder ...@@ -457,7 +462,7 @@ class Builder extends BaseBuilder
/** /**
* Insert a new record into the database. * Insert a new record into the database.
* *
* @param array $values * @param array $values
* @return bool * @return bool
*/ */
public function insert(array $values) public function insert(array $values)
...@@ -469,34 +474,34 @@ class Builder extends BaseBuilder ...@@ -469,34 +474,34 @@ class Builder extends BaseBuilder
foreach ($values as $value) { foreach ($values as $value) {
// As soon as we find a value that is not an array we assume the user is // As soon as we find a value that is not an array we assume the user is
// inserting a single document. // inserting a single document.
if (!is_array($value)) { if (! is_array($value)) {
$batch = false; $batch = false;
break; break;
} }
} }
if (!$batch) { if (! $batch) {
$values = [$values]; $values = [$values];
} }
// Batch insert // Batch insert
$result = $this->collection->insertMany($values); $result = $this->collection->insertMany($values);
return (1 == (int)$result->isAcknowledged()); return (1 == (int) $result->isAcknowledged());
} }
/** /**
* Insert a new record and get the value of the primary key. * Insert a new record and get the value of the primary key.
* *
* @param array $values * @param array $values
* @param string $sequence * @param string $sequence
* @return int * @return int
*/ */
public function insertGetId(array $values, $sequence = null) public function insertGetId(array $values, $sequence = null)
{ {
$result = $this->collection->insertOne($values); $result = $this->collection->insertOne($values);
if (1 == (int)$result->isAcknowledged()) { if (1 == (int) $result->isAcknowledged()) {
if (is_null($sequence)) { if (is_null($sequence)) {
$sequence = '_id'; $sequence = '_id';
} }
...@@ -509,14 +514,14 @@ class Builder extends BaseBuilder ...@@ -509,14 +514,14 @@ class Builder extends BaseBuilder
/** /**
* Update a record in the database. * Update a record in the database.
* *
* @param array $values * @param array $values
* @param array $options * @param array $options
* @return int * @return int
*/ */
public function update(array $values, array $options = []) public function update(array $values, array $options = [])
{ {
// Use $set as default operator. // Use $set as default operator.
if (!starts_with(key($values), '$')) { if (! starts_with(key($values), '$')) {
$values = ['$set' => $values]; $values = ['$set' => $values];
} }
...@@ -526,16 +531,16 @@ class Builder extends BaseBuilder ...@@ -526,16 +531,16 @@ class Builder extends BaseBuilder
/** /**
* Increment a column's value by a given amount. * Increment a column's value by a given amount.
* *
* @param string $column * @param string $column
* @param int $amount * @param int $amount
* @param array $extra * @param array $extra
* @return int * @return int
*/ */
public function increment($column, $amount = 1, array $extra = [], array $options = []) public function increment($column, $amount = 1, array $extra = [], array $options = [])
{ {
$query = ['$inc' => [$column => $amount]]; $query = ['$inc' => [$column => $amount]];
if (!empty($extra)) { if (! empty($extra)) {
$query['$set'] = $extra; $query['$set'] = $extra;
} }
...@@ -552,9 +557,9 @@ class Builder extends BaseBuilder ...@@ -552,9 +557,9 @@ class Builder extends BaseBuilder
/** /**
* Decrement a column's value by a given amount. * Decrement a column's value by a given amount.
* *
* @param string $column * @param string $column
* @param int $amount * @param int $amount
* @param array $extra * @param array $extra
* @return int * @return int
*/ */
public function decrement($column, $amount = 1, array $extra = [], array $options = []) public function decrement($column, $amount = 1, array $extra = [], array $options = [])
...@@ -565,28 +570,28 @@ class Builder extends BaseBuilder ...@@ -565,28 +570,28 @@ class Builder extends BaseBuilder
/** /**
* Get an array with the values of a given column. * Get an array with the values of a given column.
* *
* @param string $column * @param string $column
* @param string|null $key * @param string|null $key
* @return array * @return array
*/ */
public function pluck($column, $key = null) public function pluck($column, $key = null)
{ {
$results = $this->get(is_null($key) ? [$column] : [$column, $key]); $results = $this->get(is_null($key) ? [$column] : [$column, $key]);
return $results->pluck($column, $key); return $results->pluck($column,$key);
} }
/** /**
* Delete a record from the database. * Delete a record from the database.
* *
* @param mixed $id * @param mixed $id
* @return int * @return int
*/ */
public function delete($id = null) public function delete($id = null)
{ {
$wheres = $this->compileWheres(); $wheres = $this->compileWheres();
$result = $this->collection->DeleteMany($wheres); $result = $this->collection->DeleteMany($wheres);
if (1 == (int)$result->isAcknowledged()) { if (1 == (int) $result->isAcknowledged()) {
return $result->getDeletedCount(); return $result->getDeletedCount();
} }
...@@ -596,7 +601,7 @@ class Builder extends BaseBuilder ...@@ -596,7 +601,7 @@ class Builder extends BaseBuilder
/** /**
* Set the collection which the query is targeting. * Set the collection which the query is targeting.
* *
* @param string $collection * @param string $collection
* @return Builder * @return Builder
*/ */
public function from($collection) public function from($collection)
...@@ -615,15 +620,15 @@ class Builder extends BaseBuilder ...@@ -615,15 +620,15 @@ class Builder extends BaseBuilder
{ {
$result = $this->collection->drop(); $result = $this->collection->drop();
return (1 == (int)$result->ok); return (1 == (int) $result->ok);
} }
/** /**
* Get an array with the values of a given column. * Get an array with the values of a given column.
* *
* @deprecated * @deprecated
* @param string $column * @param string $column
* @param string $key * @param string $key
* @return array * @return array
*/ */
public function lists($column, $key = null) public function lists($column, $key = null)
...@@ -633,7 +638,7 @@ class Builder extends BaseBuilder ...@@ -633,7 +638,7 @@ class Builder extends BaseBuilder
// Convert ObjectID's to strings so that lists can do its work. // Convert ObjectID's to strings so that lists can do its work.
$results = $results->map(function ($item) { $results = $results->map(function ($item) {
$item['_id'] = (string)$item['_id']; $item['_id'] = (string) $item['_id'];
return $item; return $item;
}); });
...@@ -647,7 +652,7 @@ class Builder extends BaseBuilder ...@@ -647,7 +652,7 @@ class Builder extends BaseBuilder
/** /**
* Create a raw database expression. * Create a raw database expression.
* *
* @param closure $expression * @param closure $expression
* @return mixed * @return mixed
*/ */
public function raw($expression = null) public function raw($expression = null)
...@@ -655,8 +660,10 @@ class Builder extends BaseBuilder ...@@ -655,8 +660,10 @@ class Builder extends BaseBuilder
// Execute the closure on the mongodb collection // Execute the closure on the mongodb collection
if ($expression instanceof Closure) { if ($expression instanceof Closure) {
return call_user_func($expression, $this->collection); return call_user_func($expression, $this->collection);
} // Create an expression for the given value }
elseif (!is_null($expression)) {
// Create an expression for the given value
elseif (! is_null($expression)) {
return new Expression($expression); return new Expression($expression);
} }
...@@ -667,8 +674,8 @@ class Builder extends BaseBuilder ...@@ -667,8 +674,8 @@ class Builder extends BaseBuilder
/** /**
* Append one or more values to an array. * Append one or more values to an array.
* *
* @param mixed $column * @param mixed $column
* @param mixed $value * @param mixed $value
* @return int * @return int
*/ */
public function push($column, $value = null, $unique = false) public function push($column, $value = null, $unique = false)
...@@ -693,8 +700,8 @@ class Builder extends BaseBuilder ...@@ -693,8 +700,8 @@ class Builder extends BaseBuilder
/** /**
* Remove one or more values from an array. * Remove one or more values from an array.
* *
* @param mixed $column * @param mixed $column
* @param mixed $value * @param mixed $value
* @return int * @return int
*/ */
public function pull($column, $value = null) public function pull($column, $value = null)
...@@ -722,7 +729,7 @@ class Builder extends BaseBuilder ...@@ -722,7 +729,7 @@ class Builder extends BaseBuilder
*/ */
public function drop($columns) public function drop($columns)
{ {
if (!is_array($columns)) { if (! is_array($columns)) {
$columns = [$columns]; $columns = [$columns];
} }
...@@ -750,20 +757,20 @@ class Builder extends BaseBuilder ...@@ -750,20 +757,20 @@ class Builder extends BaseBuilder
/** /**
* Perform an update query. * Perform an update query.
* *
* @param array $query * @param array $query
* @param array $options * @param array $options
* @return int * @return int
*/ */
protected function performUpdate($query, array $options = []) protected function performUpdate($query, array $options = [])
{ {
// Update multiple items by default. // Update multiple items by default.
if (!array_key_exists('multiple', $options)) { if (! array_key_exists('multiple', $options)) {
$options['multiple'] = true; $options['multiple'] = true;
} }
$wheres = $this->compileWheres(); $wheres = $this->compileWheres();
$result = $this->collection->UpdateMany($wheres, $query, $options); $result = $this->collection->UpdateMany($wheres, $query, $options);
if (1 == (int)$result->isAcknowledged()) { if (1 == (int) $result->isAcknowledged()) {
return $result->getModifiedCount() ? $result->getModifiedCount() : $result->getUpsertedCount(); return $result->getModifiedCount() ? $result->getModifiedCount() : $result->getUpsertedCount();
} }
...@@ -788,10 +795,10 @@ class Builder extends BaseBuilder ...@@ -788,10 +795,10 @@ class Builder extends BaseBuilder
/** /**
* Add a basic where clause to the query. * Add a basic where clause to the query.
* *
* @param string $column * @param string $column
* @param string $operator * @param string $operator
* @param mixed $value * @param mixed $value
* @param string $boolean * @param string $boolean
* @return \Illuminate\Database\Query\Builder|static * @return \Illuminate\Database\Query\Builder|static
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
...@@ -832,14 +839,14 @@ class Builder extends BaseBuilder ...@@ -832,14 +839,14 @@ class Builder extends BaseBuilder
// Operator conversions // Operator conversions
$convert = [ $convert = [
'regexp' => 'regex', 'regexp' => 'regex',
'elemmatch' => 'elemMatch', 'elemmatch' => 'elemMatch',
'geointersects' => 'geoIntersects', 'geointersects' => 'geoIntersects',
'geowithin' => 'geoWithin', 'geowithin' => 'geoWithin',
'nearsphere' => 'nearSphere', 'nearsphere' => 'nearSphere',
'maxdistance' => 'maxDistance', 'maxdistance' => 'maxDistance',
'centersphere' => 'centerSphere', 'centersphere' => 'centerSphere',
'uniquedocs' => 'uniqueDocs', 'uniquedocs' => 'uniqueDocs',
]; ];
if (array_key_exists($where['operator'], $convert)) { if (array_key_exists($where['operator'], $convert)) {
...@@ -854,7 +861,9 @@ class Builder extends BaseBuilder ...@@ -854,7 +861,9 @@ class Builder extends BaseBuilder
foreach ($where['values'] as &$value) { foreach ($where['values'] as &$value) {
$value = $this->convertKey($value); $value = $this->convertKey($value);
} }
} // Single value. }
// Single value.
elseif (isset($where['value'])) { elseif (isset($where['value'])) {
$where['value'] = $this->convertKey($where['value']); $where['value'] = $this->convertKey($where['value']);
} }
...@@ -906,18 +915,20 @@ class Builder extends BaseBuilder ...@@ -906,18 +915,20 @@ class Builder extends BaseBuilder
$regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value)); $regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value));
// Convert like to regular expression. // Convert like to regular expression.
if (!starts_with($value, '%')) { if (! starts_with($value, '%')) {
$regex = '^' . $regex; $regex = '^' . $regex;
} }
if (!ends_with($value, '%')) { if (! ends_with($value, '%')) {
$regex = $regex . '$'; $regex = $regex . '$';
} }
$value = new Regex($regex, 'i'); $value = new Regex($regex, 'i');
} // Manipulate regexp operations. }
// Manipulate regexp operations.
elseif (in_array($operator, ['regexp', 'not regexp', 'regex', 'not regex'])) { elseif (in_array($operator, ['regexp', 'not regexp', 'regex', 'not regex'])) {
// Automatically convert regular expression strings to Regex objects. // Automatically convert regular expression strings to Regex objects.
if (!$value instanceof Regex) { if (! $value instanceof Regex) {
$e = explode('/', $value); $e = explode('/', $value);
$flag = end($e); $flag = end($e);
$regstr = substr($value, 1, -(strlen($flag) + 1)); $regstr = substr($value, 1, -(strlen($flag) + 1));
...@@ -931,7 +942,7 @@ class Builder extends BaseBuilder ...@@ -931,7 +942,7 @@ class Builder extends BaseBuilder
} }
} }
if (!isset($operator) or $operator == '=') { if (! isset($operator) or $operator == '=') {
$query = [$column => $value]; $query = [$column => $value];
} elseif (array_key_exists($operator, $this->conversion)) { } elseif (array_key_exists($operator, $this->conversion)) {
$query = [$column => [$this->conversion[$operator] => $value]]; $query = [$column => [$this->conversion[$operator] => $value]];
...@@ -1016,8 +1027,8 @@ class Builder extends BaseBuilder ...@@ -1016,8 +1027,8 @@ class Builder extends BaseBuilder
/** /**
* Handle dynamic method calls into the method. * Handle dynamic method calls into the method.
* *
* @param string $method * @param string $method
* @param array $parameters * @param array $parameters
* @return mixed * @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
......
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