Commit e4816615 authored by Jens Segers's avatar Jens Segers

Style fixes

parent 7a85d920
<?php namespace Jenssegers\Mongodb\Auth; <?php
namespace Jenssegers\Mongodb\Auth;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
......
<?php namespace Jenssegers\Mongodb\Auth; <?php
namespace Jenssegers\Mongodb\Auth;
use Illuminate\Auth\Passwords\PasswordResetServiceProvider as BasePasswordResetServiceProvider; use Illuminate\Auth\Passwords\PasswordResetServiceProvider as BasePasswordResetServiceProvider;
......
<?php namespace Jenssegers\Mongodb\Auth; <?php
namespace Jenssegers\Mongodb\Auth;
use Illuminate\Auth\Authenticatable; use Illuminate\Auth\Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Model;
use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Jenssegers\Mongodb\Eloquent\Model as Model;
class User extends Model implements class User extends Model implements
AuthenticatableContract, AuthenticatableContract,
......
<?php namespace Jenssegers\Mongodb; <?php
namespace Jenssegers\Mongodb;
use Exception; use Exception;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
...@@ -21,7 +23,7 @@ class Collection ...@@ -21,7 +23,7 @@ class Collection
protected $collection; protected $collection;
/** /**
* @param Connection $connection * @param Connection $connection
* @param MongoCollection $collection * @param MongoCollection $collection
*/ */
public function __construct(Connection $connection, MongoCollection $collection) public function __construct(Connection $connection, MongoCollection $collection)
...@@ -34,7 +36,7 @@ class Collection ...@@ -34,7 +36,7 @@ class Collection
* Handle dynamic method calls. * Handle dynamic method calls.
* *
* @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)
...@@ -53,7 +55,7 @@ class Collection ...@@ -53,7 +55,7 @@ class Collection
// Convert the query parameters to a json string. // Convert the query parameters to a json string.
array_walk_recursive($parameters, function (&$item, $key) { array_walk_recursive($parameters, function (&$item, $key) {
if ($item instanceof ObjectID) { if ($item instanceof ObjectID) {
$item = (string) $item; $item = (string)$item;
} }
}); });
...@@ -66,7 +68,7 @@ class Collection ...@@ -66,7 +68,7 @@ class Collection
} }
} }
$queryString = $this->collection->getCollectionName().'.'.$method.'('.implode(',', $query).')'; $queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')';
$this->connection->logQuery($queryString, [], $time); $this->connection->logQuery($queryString, [], $time);
} }
......
<?php namespace Jenssegers\Mongodb; <?php
namespace Jenssegers\Mongodb;
use Illuminate\Database\Connection as BaseConnection; use Illuminate\Database\Connection as BaseConnection;
use MongoDB\Client; use MongoDB\Client;
...@@ -114,8 +116,8 @@ class Connection extends BaseConnection ...@@ -114,8 +116,8 @@ class Connection extends BaseConnection
* Create a new MongoDB connection. * Create a new MongoDB connection.
* *
* @param string $dsn * @param string $dsn
* @param array $config * @param array $config
* @param array $options * @param array $options
* @return \MongoDB\Client * @return \MongoDB\Client
*/ */
protected function createConnection($dsn, array $config, array $options) protected function createConnection($dsn, array $config, array $options)
...@@ -128,10 +130,10 @@ class Connection extends BaseConnection ...@@ -128,10 +130,10 @@ class Connection extends BaseConnection
} }
// Check if the credentials are not already set in the options // Check if the credentials are not already set in the options
if (! isset($options['username']) && ! empty($config['username'])) { if (!isset($options['username']) && !empty($config['username'])) {
$options['username'] = $config['username']; $options['username'] = $config['username'];
} }
if (! isset($options['password']) && ! empty($config['password'])) { if (!isset($options['password']) && !empty($config['password'])) {
$options['password'] = $config['password']; $options['password'] = $config['password'];
} }
...@@ -155,7 +157,7 @@ class Connection extends BaseConnection ...@@ -155,7 +157,7 @@ class Connection extends BaseConnection
protected function getDsn(array $config) protected function getDsn(array $config)
{ {
// Check if the user passed a complete dsn to the configuration. // Check if the user passed a complete dsn to the configuration.
if (! empty($config['dsn'])) { if (!empty($config['dsn'])) {
return $config['dsn']; return $config['dsn'];
} }
...@@ -164,15 +166,15 @@ class Connection extends BaseConnection ...@@ -164,15 +166,15 @@ class Connection extends BaseConnection
foreach ($hosts as &$host) { foreach ($hosts as &$host) {
// Check if we need to add a port to the host // Check if we need to add a port to the host
if (strpos($host, ':') === false && ! empty($config['port'])) { if (strpos($host, ':') === false && !empty($config['port'])) {
$host = $host.':'.$config['port']; $host = $host . ':' . $config['port'];
} }
} }
// Check if we want to authenticate against a specific database. // Check if we want to authenticate against a specific database.
$auth_database = isset($config['options']) && ! empty($config['options']['database']) ? $config['options']['database'] : null; $auth_database = isset($config['options']) && !empty($config['options']['database']) ? $config['options']['database'] : null;
return 'mongodb://'.implode(',', $hosts).($auth_database ? '/'.$auth_database : ''); return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : '');
} }
/** /**
...@@ -219,7 +221,7 @@ class Connection extends BaseConnection ...@@ -219,7 +221,7 @@ class Connection extends BaseConnection
* Dynamically pass methods to the connection. * Dynamically pass methods to the connection.
* *
* @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)
......
<?php namespace Jenssegers\Mongodb\Eloquent; <?php
namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Jenssegers\Mongodb\Helpers\QueriesRelationships; use Jenssegers\Mongodb\Helpers\QueriesRelationships;
...@@ -8,6 +10,7 @@ use MongoDB\Model\BSONDocument; ...@@ -8,6 +10,7 @@ use MongoDB\Model\BSONDocument;
class Builder extends EloquentBuilder class Builder extends EloquentBuilder
{ {
use QueriesRelationships; use QueriesRelationships;
/** /**
* The methods that should be returned from query builder. * The methods that should be returned from query builder.
* *
...@@ -157,10 +160,10 @@ class Builder extends EloquentBuilder ...@@ -157,10 +160,10 @@ class Builder extends EloquentBuilder
elseif ($results instanceof BSONDocument) { elseif ($results instanceof BSONDocument) {
$results = $results->getArrayCopy(); $results = $results->getArrayCopy();
return $this->model->newFromBuilder((array) $results); return $this->model->newFromBuilder((array)$results);
} // The result is a single object. } // The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results)) { elseif (is_array($results) and array_key_exists('_id', $results)) {
return $this->model->newFromBuilder((array) $results); return $this->model->newFromBuilder((array)$results);
} }
return $results; return $results;
......
<?php namespace Jenssegers\Mongodb\Eloquent; <?php
namespace Jenssegers\Mongodb\Eloquent;
use Jenssegers\Mongodb\Relations\EmbedsMany; use Jenssegers\Mongodb\Relations\EmbedsMany;
use Jenssegers\Mongodb\Relations\EmbedsOne; use Jenssegers\Mongodb\Relations\EmbedsOne;
......
<?php namespace Jenssegers\Mongodb\Eloquent; <?php
namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
...@@ -23,7 +25,7 @@ trait HybridRelations ...@@ -23,7 +25,7 @@ trait HybridRelations
public function hasOne($related, $foreignKey = null, $localKey = null) public function hasOne($related, $foreignKey = null, $localKey = null)
{ {
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::hasOne($related, $foreignKey, $localKey); return parent::hasOne($related, $foreignKey, $localKey);
} }
...@@ -49,7 +51,7 @@ trait HybridRelations ...@@ -49,7 +51,7 @@ trait HybridRelations
public function morphOne($related, $name, $type = null, $id = null, $localKey = null) public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
{ {
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::morphOne($related, $name, $type, $id, $localKey); return parent::morphOne($related, $name, $type, $id, $localKey);
} }
...@@ -73,7 +75,7 @@ trait HybridRelations ...@@ -73,7 +75,7 @@ trait HybridRelations
public function hasMany($related, $foreignKey = null, $localKey = null) public function hasMany($related, $foreignKey = null, $localKey = null)
{ {
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::hasMany($related, $foreignKey, $localKey); return parent::hasMany($related, $foreignKey, $localKey);
} }
...@@ -99,7 +101,7 @@ trait HybridRelations ...@@ -99,7 +101,7 @@ trait HybridRelations
public function morphMany($related, $name, $type = null, $id = null, $localKey = null) public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
{ {
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::morphMany($related, $name, $type, $id, $localKey); return parent::morphMany($related, $name, $type, $id, $localKey);
} }
...@@ -138,7 +140,7 @@ trait HybridRelations ...@@ -138,7 +140,7 @@ trait HybridRelations
} }
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::belongsTo($related, $foreignKey, $otherKey, $relation); return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
} }
...@@ -146,7 +148,7 @@ trait HybridRelations ...@@ -146,7 +148,7 @@ trait HybridRelations
// foreign key name by using the name of the relationship function, which // foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns. // when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey)) { if (is_null($foreignKey)) {
$foreignKey = Str::snake($relation).'_id'; $foreignKey = Str::snake($relation) . '_id';
} }
$instance = new $related; $instance = new $related;
...@@ -225,18 +227,18 @@ trait HybridRelations ...@@ -225,18 +227,18 @@ trait HybridRelations
} }
// Check if it is a relation with an original model. // Check if it is a relation with an original model.
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) { if (!is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation); return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
} }
// First, we'll need to determine the foreign key and "other key" for the // First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query // relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this. // instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey().'s'; $foreignKey = $foreignKey ?: $this->getForeignKey() . 's';
$instance = new $related; $instance = new $related;
$otherKey = $otherKey ?: $instance->getForeignKey().'s'; $otherKey = $otherKey ?: $instance->getForeignKey() . 's';
// If no table name was provided, we can guess it by concatenating the two // If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names // models using underscores in alphabetical order. The two model names
......
<?php namespace Jenssegers\Mongodb\Eloquent; <?php
namespace Jenssegers\Mongodb\Eloquent;
use Carbon\Carbon; use Carbon\Carbon;
use DateTime; use DateTime;
...@@ -44,13 +46,13 @@ abstract class Model extends BaseModel ...@@ -44,13 +46,13 @@ abstract class Model extends BaseModel
{ {
// If we don't have a value for 'id', we will use the Mongo '_id' value. // If we don't have a value for 'id', we will use the Mongo '_id' value.
// This allows us to work with models in a more sql-like way. // This allows us to work with models in a more sql-like way.
if (! $value and array_key_exists('_id', $this->attributes)) { if (!$value and array_key_exists('_id', $this->attributes)) {
$value = $this->attributes['_id']; $value = $this->attributes['_id'];
} }
// Convert ObjectID to string. // Convert ObjectID to string.
if ($value instanceof ObjectID) { if ($value instanceof ObjectID) {
return (string) $value; return (string)$value;
} }
return $value; return $value;
...@@ -75,7 +77,7 @@ abstract class Model extends BaseModel ...@@ -75,7 +77,7 @@ abstract class Model extends BaseModel
} }
// Let Eloquent convert the value to a DateTime instance. // Let Eloquent convert the value to a DateTime instance.
if (! $value instanceof DateTime) { if (!$value instanceof DateTime) {
$value = parent::asDateTime($value); $value = parent::asDateTime($value);
} }
...@@ -124,7 +126,7 @@ abstract class Model extends BaseModel ...@@ -124,7 +126,7 @@ abstract class Model extends BaseModel
*/ */
public function getAttribute($key) public function getAttribute($key)
{ {
if (! $key) { if (!$key) {
return; return;
} }
...@@ -134,7 +136,7 @@ abstract class Model extends BaseModel ...@@ -134,7 +136,7 @@ abstract class Model extends BaseModel
} }
// This checks for embedded relation support. // This checks for embedded relation support.
if (method_exists($this, $key) and ! method_exists(self::class, $key)) { if (method_exists($this, $key) and !method_exists(self::class, $key)) {
return $this->getRelationValue($key); return $this->getRelationValue($key);
} }
...@@ -191,14 +193,14 @@ abstract class Model extends BaseModel ...@@ -191,14 +193,14 @@ abstract class Model extends BaseModel
// nicely when your models are converted to JSON. // nicely when your models are converted to JSON.
foreach ($attributes as $key => &$value) { foreach ($attributes as $key => &$value) {
if ($value instanceof ObjectID) { if ($value instanceof ObjectID) {
$value = (string) $value; $value = (string)$value;
} }
} }
// Convert dot-notation dates. // Convert dot-notation dates.
foreach ($this->getDates() as $key) { foreach ($this->getDates() as $key) {
if (str_contains($key, '.') and array_has($attributes, $key)) { if (str_contains($key, '.') and array_has($attributes, $key)) {
array_set($attributes, $key, (string) $this->asDateTime(array_get($attributes, $key))); array_set($attributes, $key, (string)$this->asDateTime(array_get($attributes, $key)));
} }
} }
...@@ -240,7 +242,7 @@ abstract class Model extends BaseModel ...@@ -240,7 +242,7 @@ abstract class Model extends BaseModel
*/ */
public function drop($columns) public function drop($columns)
{ {
if (! is_array($columns)) { if (!is_array($columns)) {
$columns = [$columns]; $columns = [$columns];
} }
...@@ -268,7 +270,7 @@ abstract class Model extends BaseModel ...@@ -268,7 +270,7 @@ abstract class Model extends BaseModel
} }
// Do batch push by default. // Do batch push by default.
if (! is_array($values)) { if (!is_array($values)) {
$values = [$values]; $values = [$values];
} }
...@@ -286,13 +288,13 @@ abstract class Model extends BaseModel ...@@ -286,13 +288,13 @@ abstract class Model extends BaseModel
* Remove one or more values from an array. * Remove one or more values from an array.
* *
* @param string $column * @param string $column
* @param mixed $values * @param mixed $values
* @return mixed * @return mixed
*/ */
public function pull($column, $values) public function pull($column, $values)
{ {
// Do batch pull by default. // Do batch pull by default.
if (! is_array($values)) { if (!is_array($values)) {
$values = [$values]; $values = [$values];
} }
...@@ -307,8 +309,8 @@ abstract class Model extends BaseModel ...@@ -307,8 +309,8 @@ abstract class Model extends BaseModel
* Append one or more values to the underlying attribute value and sync with original. * Append one or more values to the underlying attribute value and sync with original.
* *
* @param string $column * @param string $column
* @param array $values * @param array $values
* @param bool $unique * @param bool $unique
*/ */
protected function pushAttributeValues($column, array $values, $unique = false) protected function pushAttributeValues($column, array $values, $unique = false)
{ {
...@@ -332,7 +334,7 @@ abstract class Model extends BaseModel ...@@ -332,7 +334,7 @@ abstract class Model extends BaseModel
* Remove one or more values to the underlying attribute value and sync with original. * Remove one or more values to the underlying attribute value and sync with original.
* *
* @param string $column * @param string $column
* @param array $values * @param array $values
*/ */
protected function pullAttributeValues($column, array $values) protected function pullAttributeValues($column, array $values)
{ {
...@@ -356,7 +358,7 @@ abstract class Model extends BaseModel ...@@ -356,7 +358,7 @@ abstract class Model extends BaseModel
*/ */
public function getForeignKey() public function getForeignKey()
{ {
return Str::snake(class_basename($this)).'_'.ltrim($this->primaryKey, '_'); return Str::snake(class_basename($this)) . '_' . ltrim($this->primaryKey, '_');
} }
/** /**
......
<?php namespace Jenssegers\Mongodb\Eloquent; <?php
namespace Jenssegers\Mongodb\Eloquent;
trait SoftDeletes trait SoftDeletes
{ {
......
...@@ -86,7 +86,7 @@ trait QueriesRelationships ...@@ -86,7 +86,7 @@ trait QueriesRelationships
$not = in_array($operator, ['<', '<=', '!=']); $not = in_array($operator, ['<', '<=', '!=']);
// If we are comparing to 0, we need an additional $not flip. // If we are comparing to 0, we need an additional $not flip.
if ($count == 0) { if ($count == 0) {
$not = ! $not; $not = !$not;
} }
$relations = $hasQuery->pluck($this->getHasCompareKey($relation)); $relations = $hasQuery->pluck($this->getHasCompareKey($relation));
...@@ -112,7 +112,7 @@ trait QueriesRelationships ...@@ -112,7 +112,7 @@ trait QueriesRelationships
return $relation->getForeignKey(); return $relation->getForeignKey();
} }
throw new \Exception(class_basename($relation).' Is Not supported for hybrid query constraints!'); throw new \Exception(class_basename($relation) . ' Is Not supported for hybrid query constraints!');
} }
/** /**
...@@ -137,7 +137,7 @@ trait QueriesRelationships ...@@ -137,7 +137,7 @@ trait QueriesRelationships
protected function getConstrainedRelatedIds($relations, $operator, $count) protected function getConstrainedRelatedIds($relations, $operator, $count)
{ {
$relationCount = array_count_values(array_map(function ($id) { $relationCount = array_count_values(array_map(function ($id) {
return (string) $id; // Convert Back ObjectIds to Strings return (string)$id; // Convert Back ObjectIds to Strings
}, is_array($relations) ? $relations : $relations->flatten()->toArray())); }, is_array($relations) ? $relations : $relations->flatten()->toArray()));
// Remove unwanted related objects based on the operator and count. // Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) { $relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {
......
<?php namespace Jenssegers\Mongodb; <?php
namespace Jenssegers\Mongodb;
use Illuminate\Queue\QueueServiceProvider; use Illuminate\Queue\QueueServiceProvider;
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider; use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
......
<?php namespace Jenssegers\Mongodb; <?php
namespace Jenssegers\Mongodb;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Jenssegers\Mongodb\Eloquent\Model; use Jenssegers\Mongodb\Eloquent\Model;
......
<?php namespace Jenssegers\Mongodb\Query; <?php
namespace Jenssegers\Mongodb\Query;
use Closure; use Closure;
use DateTime; use DateTime;
...@@ -237,18 +239,18 @@ class Builder extends BaseBuilder ...@@ -237,18 +239,18 @@ class Builder extends BaseBuilder
// Add grouping columns to the $group part of the aggregation pipeline. // Add grouping columns to the $group part of the aggregation pipeline.
if ($this->groups) { if ($this->groups) {
foreach ($this->groups as $column) { foreach ($this->groups as $column) {
$group['_id'][$column] = '$'.$column; $group['_id'][$column] = '$' . $column;
// When grouping, also add the $last operator to each grouped field, // When grouping, also add the $last operator to each grouped field,
// this mimics MySQL's behaviour a bit. // this mimics MySQL's behaviour a bit.
$group[$column] = ['$last' => '$'.$column]; $group[$column] = ['$last' => '$' . $column];
} }
// Do the same for other columns that are selected. // Do the same for other columns that are selected.
foreach ($this->columns as $column) { foreach ($this->columns as $column) {
$key = str_replace('.', '_', $column); $key = str_replace('.', '_', $column);
$group[$key] = ['$last' => '$'.$column]; $group[$key] = ['$last' => '$' . $column];
} }
} }
...@@ -270,7 +272,7 @@ class Builder extends BaseBuilder ...@@ -270,7 +272,7 @@ class Builder extends BaseBuilder
$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];
} }
} }
} }
...@@ -296,7 +298,7 @@ class Builder extends BaseBuilder ...@@ -296,7 +298,7 @@ class Builder extends BaseBuilder
// apply unwinds for subdocument array aggregation // apply unwinds for subdocument array aggregation
foreach ($unwinds as $unwind) { foreach ($unwinds as $unwind) {
$pipeline[] = ['$unwind' => '$'.$unwind]; $pipeline[] = ['$unwind' => '$' . $unwind];
} }
if ($group) { if ($group) {
...@@ -422,28 +424,28 @@ class Builder extends BaseBuilder ...@@ -422,28 +424,28 @@ class Builder extends BaseBuilder
public function aggregate($function, $columns = []) public function aggregate($function, $columns = [])
{ {
$this->aggregate = compact('function', 'columns'); $this->aggregate = compact('function', 'columns');
$previousColumns = $this->columns; $previousColumns = $this->columns;
// We will also back up the select bindings since the select clause will be // We will also back up the select bindings since the select clause will be
// removed when performing the aggregate function. Once the query is run // removed when performing the aggregate function. Once the query is run
// we will add the bindings back onto this query so they can get used. // we will add the bindings back onto this query so they can get used.
$previousSelectBindings = $this->bindings['select']; $previousSelectBindings = $this->bindings['select'];
$this->bindings['select'] = []; $this->bindings['select'] = [];
$results = $this->get($columns); $results = $this->get($columns);
// Once we have executed the query, we will reset the aggregate property so // Once we have executed the query, we will reset the aggregate property so
// that more select queries can be executed against the database without // that more select queries can be executed against the database without
// the aggregate value getting in the way when the grammar builds it. // the aggregate value getting in the way when the grammar builds it.
$this->aggregate = null; $this->aggregate = null;
$this->columns = $previousColumns; $this->columns = $previousColumns;
$this->bindings['select'] = $previousSelectBindings; $this->bindings['select'] = $previousSelectBindings;
if (isset($results[0])) { if (isset($results[0])) {
$result = (array) $results[0]; $result = (array)$results[0];
return $result['aggregate']; return $result['aggregate'];
} }
} }
...@@ -453,7 +455,7 @@ class Builder extends BaseBuilder ...@@ -453,7 +455,7 @@ class Builder extends BaseBuilder
*/ */
public function exists() public function exists()
{ {
return ! is_null($this->first()); return !is_null($this->first());
} }
/** /**
...@@ -522,20 +524,20 @@ class Builder extends BaseBuilder ...@@ -522,20 +524,20 @@ 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());
} }
/** /**
...@@ -545,7 +547,7 @@ class Builder extends BaseBuilder ...@@ -545,7 +547,7 @@ class Builder extends BaseBuilder
{ {
$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';
} }
...@@ -561,7 +563,7 @@ class Builder extends BaseBuilder ...@@ -561,7 +563,7 @@ class Builder extends BaseBuilder
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];
} }
...@@ -575,7 +577,7 @@ class Builder extends BaseBuilder ...@@ -575,7 +577,7 @@ class Builder extends BaseBuilder
{ {
$query = ['$inc' => [$column => $amount]]; $query = ['$inc' => [$column => $amount]];
if (! empty($extra)) { if (!empty($extra)) {
$query['$set'] = $extra; $query['$set'] = $extra;
} }
...@@ -607,7 +609,7 @@ class Builder extends BaseBuilder ...@@ -607,7 +609,7 @@ class Builder extends BaseBuilder
// Convert ObjectID's to strings // Convert ObjectID's to strings
if ($key == '_id') { if ($key == '_id') {
$results = $results->map(function ($item) { $results = $results->map(function ($item) {
$item['_id'] = (string) $item['_id']; $item['_id'] = (string)$item['_id'];
return $item; return $item;
}); });
} }
...@@ -624,13 +626,13 @@ class Builder extends BaseBuilder ...@@ -624,13 +626,13 @@ class Builder extends BaseBuilder
// If an ID is passed to the method, we will set the where clause to check // If an ID is passed to the method, we will set the where clause to check
// the ID to allow developers to simply and quickly remove a single row // the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses. // from their database without manually specifying the where clauses.
if (! is_null($id)) { if (!is_null($id)) {
$this->where('_id', '=', $id); $this->where('_id', '=', $id);
} }
$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();
} }
...@@ -656,7 +658,7 @@ class Builder extends BaseBuilder ...@@ -656,7 +658,7 @@ class Builder extends BaseBuilder
{ {
$result = $this->collection->drop(); $result = $this->collection->drop();
return (1 == (int) $result->ok); return (1 == (int)$result->ok);
} }
/** /**
...@@ -681,7 +683,7 @@ class Builder extends BaseBuilder ...@@ -681,7 +683,7 @@ class Builder extends BaseBuilder
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 } // Create an expression for the given value
elseif (! is_null($expression)) { elseif (!is_null($expression)) {
return new Expression($expression); return new Expression($expression);
} }
...@@ -694,7 +696,7 @@ class Builder extends BaseBuilder ...@@ -694,7 +696,7 @@ class Builder extends BaseBuilder
* *
* @param mixed $column * @param mixed $column
* @param mixed $value * @param mixed $value
* @param bool $unique * @param bool $unique
* @return int * @return int
*/ */
public function push($column, $value = null, $unique = false) public function push($column, $value = null, $unique = false)
...@@ -748,7 +750,7 @@ class Builder extends BaseBuilder ...@@ -748,7 +750,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];
} }
...@@ -781,13 +783,13 @@ class Builder extends BaseBuilder ...@@ -781,13 +783,13 @@ class Builder extends BaseBuilder
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();
} }
...@@ -936,18 +938,18 @@ class Builder extends BaseBuilder ...@@ -936,18 +938,18 @@ 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));
...@@ -961,12 +963,12 @@ class Builder extends BaseBuilder ...@@ -961,12 +963,12 @@ 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]];
} else { } else {
$query = [$column => ['$'.$operator => $value]]; $query = [$column => ['$' . $operator => $value]];
} }
return $query; return $query;
......
<?php namespace Jenssegers\Mongodb\Query; <?php
namespace Jenssegers\Mongodb\Query;
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar; use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
......
<?php namespace Jenssegers\Mongodb\Query; <?php
namespace Jenssegers\Mongodb\Query;
use Illuminate\Database\Query\Processors\Processor as BaseProcessor; use Illuminate\Database\Query\Processors\Processor as BaseProcessor;
......
<?php namespace Jenssegers\Mongodb\Queue\Failed; <?php
namespace Jenssegers\Mongodb\Queue\Failed;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Queue\Failed\DatabaseFailedJobProvider; use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
...@@ -31,7 +33,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider ...@@ -31,7 +33,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
$all = $this->getTable()->orderBy('_id', 'desc')->get()->all(); $all = $this->getTable()->orderBy('_id', 'desc')->get()->all();
$all = array_map(function ($job) { $all = array_map(function ($job) {
$job['id'] = (string) $job['_id']; $job['id'] = (string)$job['_id'];
return $job; return $job;
}, $all); }, $all);
...@@ -41,14 +43,14 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider ...@@ -41,14 +43,14 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
/** /**
* Get a single failed job. * Get a single failed job.
* *
* @param mixed $id * @param mixed $id
* @return array * @return array
*/ */
public function find($id) public function find($id)
{ {
$job = $this->getTable()->find($id); $job = $this->getTable()->find($id);
$job['id'] = (string) $job['_id']; $job['id'] = (string)$job['_id'];
return $job; return $job;
} }
...@@ -56,7 +58,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider ...@@ -56,7 +58,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
/** /**
* Delete a single failed job from storage. * Delete a single failed job from storage.
* *
* @param mixed $id * @param mixed $id
* @return bool * @return bool
*/ */
public function forget($id) public function forget($id)
......
<?php namespace Jenssegers\Mongodb\Queue; <?php
namespace Jenssegers\Mongodb\Queue;
use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Queue\Connectors\ConnectorInterface; use Illuminate\Queue\Connectors\ConnectorInterface;
...@@ -16,8 +18,7 @@ class MongoConnector implements ConnectorInterface ...@@ -16,8 +18,7 @@ class MongoConnector implements ConnectorInterface
/** /**
* Create a new connector instance. * Create a new connector instance.
* *
* @param \Illuminate\Database\ConnectionResolverInterface $connections * @param \Illuminate\Database\ConnectionResolverInterface $connections
* @return void
*/ */
public function __construct(ConnectionResolverInterface $connections) public function __construct(ConnectionResolverInterface $connections)
{ {
...@@ -27,7 +28,7 @@ class MongoConnector implements ConnectorInterface ...@@ -27,7 +28,7 @@ class MongoConnector implements ConnectorInterface
/** /**
* Establish a queue connection. * Establish a queue connection.
* *
* @param array $config * @param array $config
* @return \Illuminate\Contracts\Queue\Queue * @return \Illuminate\Contracts\Queue\Queue
*/ */
public function connect(array $config) public function connect(array $config)
......
<?php namespace Jenssegers\Mongodb\Queue; <?php
namespace Jenssegers\Mongodb\Queue;
use Illuminate\Queue\Jobs\DatabaseJob; use Illuminate\Queue\Jobs\DatabaseJob;
......
<?php namespace Jenssegers\Mongodb\Queue; <?php
namespace Jenssegers\Mongodb\Queue;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Queue\DatabaseQueue; use Illuminate\Queue\DatabaseQueue;
...@@ -37,7 +39,7 @@ class MongoQueue extends DatabaseQueue ...@@ -37,7 +39,7 @@ class MongoQueue extends DatabaseQueue
{ {
$queue = $this->getQueue($queue); $queue = $this->getQueue($queue);
if (! is_null($this->retryAfter)) { if (!is_null($this->retryAfter)) {
$this->releaseJobsThatHaveBeenReservedTooLong($queue); $this->releaseJobsThatHaveBeenReservedTooLong($queue);
} }
...@@ -124,7 +126,7 @@ class MongoQueue extends DatabaseQueue ...@@ -124,7 +126,7 @@ class MongoQueue extends DatabaseQueue
* Release the given job ID from reservation. * Release the given job ID from reservation.
* *
* @param string $id * @param string $id
* @param int $attempts * @param int $attempts
* @return void * @return void
*/ */
protected function releaseJob($id, $attempts) protected function releaseJob($id, $attempts)
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
...@@ -144,8 +146,8 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -144,8 +146,8 @@ class BelongsToMany extends EloquentBelongsToMany
if ($detaching and count($detach) > 0) { if ($detaching and count($detach) > 0) {
$this->detach($detach); $this->detach($detach);
$changes['detached'] = (array) array_map(function ($v) { $changes['detached'] = (array)array_map(function ($v) {
return is_numeric($v) ? (int) $v : (string) $v; return is_numeric($v) ? (int)$v : (string)$v;
}, $detach); }, $detach);
} }
...@@ -190,14 +192,14 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -190,14 +192,14 @@ class BelongsToMany extends EloquentBelongsToMany
$query = $this->newRelatedQuery(); $query = $this->newRelatedQuery();
$query->whereIn($this->related->getKeyName(), (array) $id); $query->whereIn($this->related->getKeyName(), (array)$id);
// Attach the new parent id to the related model. // Attach the new parent id to the related model.
$query->push($this->foreignKey, $this->parent->getKey(), true); $query->push($this->foreignKey, $this->parent->getKey(), true);
} }
// Attach the new ids to the parent model. // Attach the new ids to the parent model.
$this->parent->push($this->getRelatedKey(), (array) $id, true); $this->parent->push($this->getRelatedKey(), (array)$id, true);
if ($touch) { if ($touch) {
$this->touchIfTouching(); $this->touchIfTouching();
...@@ -210,7 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -210,7 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany
public function detach($ids = [], $touch = true) public function detach($ids = [], $touch = true)
{ {
if ($ids instanceof Model) { if ($ids instanceof Model) {
$ids = (array) $ids->getKey(); $ids = (array)$ids->getKey();
} }
$query = $this->newRelatedQuery(); $query = $this->newRelatedQuery();
...@@ -218,7 +220,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -218,7 +220,7 @@ class BelongsToMany extends EloquentBelongsToMany
// If associated IDs were passed to the method we will only delete those // If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken. // associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes. // We'll return the numbers of affected rows when we do the deletes.
$ids = (array) $ids; $ids = (array)$ids;
// Detach all ids from the parent model. // Detach all ids from the parent model.
$this->parent->pull($this->getRelatedKey(), $ids); $this->parent->pull($this->getRelatedKey(), $ids);
...@@ -307,7 +309,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -307,7 +309,7 @@ class BelongsToMany extends EloquentBelongsToMany
{ {
$results = []; $results = [];
foreach ($records as $id => $attributes) { foreach ($records as $id => $attributes) {
if (! is_array($attributes)) { if (!is_array($attributes)) {
list($id, $attributes) = [$attributes, []]; list($id, $attributes) = [$attributes, []];
} }
$results[$id] = $attributes; $results[$id] = $attributes;
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
...@@ -37,7 +39,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -37,7 +39,7 @@ class EmbedsMany extends EmbedsOneOrMany
public function performInsert(Model $model) public function performInsert(Model $model)
{ {
// Generate a new key if needed. // Generate a new key if needed.
if ($model->getKeyName() == '_id' and ! $model->getKey()) { if ($model->getKeyName() == '_id' and !$model->getKey()) {
$model->setAttribute('_id', new ObjectID); $model->setAttribute('_id', new ObjectID);
} }
...@@ -77,10 +79,10 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -77,10 +79,10 @@ class EmbedsMany extends EmbedsOneOrMany
$foreignKey = $this->getForeignKeyValue($model); $foreignKey = $this->getForeignKeyValue($model);
// Use array dot notation for better update behavior. // Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey.'.$.'); $values = array_dot($model->getDirty(), $this->localKey . '.$.');
// Update document in database. // Update document in database.
$result = $this->getBaseQuery()->where($this->localKey.'.'.$model->getKeyName(), $foreignKey) $result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey)
->update($values); ->update($values);
// Attach the model to its parent. // Attach the model to its parent.
...@@ -126,7 +128,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -126,7 +128,7 @@ class EmbedsMany extends EmbedsOneOrMany
*/ */
public function associate(Model $model) public function associate(Model $model)
{ {
if (! $this->contains($model)) { if (!$this->contains($model)) {
return $this->associateNew($model); return $this->associateNew($model);
} else { } else {
return $this->associateExisting($model); return $this->associateExisting($model);
...@@ -235,7 +237,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -235,7 +237,7 @@ class EmbedsMany extends EmbedsOneOrMany
protected function associateNew($model) protected function associateNew($model)
{ {
// Create a new key if needed. // Create a new key if needed.
if (! $model->getAttribute('_id')) { if (!$model->getAttribute('_id')) {
$model->setAttribute('_id', new ObjectID); $model->setAttribute('_id', new ObjectID);
} }
...@@ -309,7 +311,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -309,7 +311,7 @@ class EmbedsMany extends EmbedsOneOrMany
*/ */
protected function setEmbedded($models) protected function setEmbedded($models)
{ {
if (! is_array($models)) { if (!is_array($models)) {
$models = [$models]; $models = [$models];
} }
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
...@@ -34,7 +36,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -34,7 +36,7 @@ class EmbedsOne extends EmbedsOneOrMany
public function performInsert(Model $model) public function performInsert(Model $model)
{ {
// Generate a new key if needed. // Generate a new key if needed.
if ($model->getKeyName() == '_id' and ! $model->getKey()) { if ($model->getKeyName() == '_id' and !$model->getKey()) {
$model->setAttribute('_id', new ObjectID); $model->setAttribute('_id', new ObjectID);
} }
...@@ -69,7 +71,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -69,7 +71,7 @@ class EmbedsOne extends EmbedsOneOrMany
} }
// Use array dot notation for better update behavior. // Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey.'.'); $values = array_dot($model->getDirty(), $this->localKey . '.');
$result = $this->getBaseQuery()->update($values); $result = $this->getBaseQuery()->update($values);
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
...@@ -32,11 +34,11 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -32,11 +34,11 @@ abstract class EmbedsOneOrMany extends Relation
* Create a new embeds many relationship instance. * Create a new embeds many relationship instance.
* *
* @param Builder $query * @param Builder $query
* @param Model $parent * @param Model $parent
* @param Model $related * @param Model $related
* @param string $localKey * @param string $localKey
* @param string $foreignKey * @param string $foreignKey
* @param string $relation * @param string $relation
*/ */
public function __construct(Builder $query, Model $parent, Model $related, $localKey, $foreignKey, $relation) public function __construct(Builder $query, Model $parent, Model $related, $localKey, $foreignKey, $relation)
{ {
...@@ -186,7 +188,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -186,7 +188,7 @@ abstract class EmbedsOneOrMany extends Relation
$ids = $ids->all(); $ids = $ids->all();
} }
if (! is_array($ids)) { if (!is_array($ids)) {
$ids = [$ids]; $ids = [$ids];
} }
...@@ -208,7 +210,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -208,7 +210,7 @@ abstract class EmbedsOneOrMany extends Relation
$attributes = $this->parent->getAttributes(); $attributes = $this->parent->getAttributes();
// Get embedded models form parent attributes. // Get embedded models form parent attributes.
$embedded = isset($attributes[$this->localKey]) ? (array) $attributes[$this->localKey] : null; $embedded = isset($attributes[$this->localKey]) ? (array)$attributes[$this->localKey] : null;
return $embedded; return $embedded;
} }
...@@ -278,7 +280,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -278,7 +280,7 @@ abstract class EmbedsOneOrMany extends Relation
return; return;
} }
$model = $this->related->newFromBuilder((array) $attributes); $model = $this->related->newFromBuilder((array)$attributes);
$model->setParentRelation($this); $model->setParentRelation($this);
...@@ -339,7 +341,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -339,7 +341,7 @@ abstract class EmbedsOneOrMany extends Relation
protected function getPathHierarchy($glue = '.') protected function getPathHierarchy($glue = '.')
{ {
if ($parentRelation = $this->getParentRelation()) { if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy($glue).$glue.$this->localKey; return $parentRelation->getPathHierarchy($glue) . $glue . $this->localKey;
} }
return $this->localKey; return $this->localKey;
...@@ -351,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -351,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation
public function getQualifiedParentKeyName() public function getQualifiedParentKeyName()
{ {
if ($parentRelation = $this->getParentRelation()) { if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy().'.'.$this->parent->getKeyName(); return $parentRelation->getPathHierarchy() . '.' . $this->parent->getKeyName();
} }
return $this->parent->getKeyName(); return $this->parent->getKeyName();
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany; use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany;
...@@ -62,8 +64,8 @@ class HasMany extends EloquentHasMany ...@@ -62,8 +64,8 @@ class HasMany extends EloquentHasMany
/** /**
* Add the constraints for a relationship query. * Add the constraints for a relationship query.
* *
* @param Builder $query * @param Builder $query
* @param Builder $parent * @param Builder $parent
* @param array|mixed $columns * @param array|mixed $columns
* @return Builder * @return Builder
*/ */
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne; use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
...@@ -62,8 +64,8 @@ class HasOne extends EloquentHasOne ...@@ -62,8 +64,8 @@ class HasOne extends EloquentHasOne
/** /**
* Add the constraints for a relationship query. * Add the constraints for a relationship query.
* *
* @param Builder $query * @param Builder $query
* @param Builder $parent * @param Builder $parent
* @param array|mixed $columns * @param array|mixed $columns
* @return Builder * @return Builder
*/ */
......
<?php namespace Jenssegers\Mongodb\Relations; <?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo; use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
......
<?php namespace Jenssegers\Mongodb\Schema; <?php
namespace Jenssegers\Mongodb\Schema;
use Illuminate\Database\Connection; use Illuminate\Database\Connection;
...@@ -84,7 +86,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -84,7 +86,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
$transform = []; $transform = [];
foreach ($columns as $column) { foreach ($columns as $column) {
$transform[$column] = $column.'_1'; $transform[$column] = $column . '_1';
} }
$columns = $transform; $columns = $transform;
...@@ -130,7 +132,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -130,7 +132,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify a sparse index for the collection. * Specify a sparse index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @param array $options * @param array $options
* @return Blueprint * @return Blueprint
*/ */
public function sparse($columns = null, $options = []) public function sparse($columns = null, $options = [])
...@@ -148,8 +150,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -148,8 +150,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify a geospatial index for the collection. * Specify a geospatial index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @param string $index * @param string $index
* @param array $options * @param array $options
* @return Blueprint * @return Blueprint
*/ */
public function geospatial($columns = null, $index = '2d', $options = []) public function geospatial($columns = null, $index = '2d', $options = [])
...@@ -174,7 +176,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -174,7 +176,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* on the given single-field index containing a date. * on the given single-field index containing a date.
* *
* @param string|array $columns * @param string|array $columns
* @param int $seconds * @param int $seconds
* @return Blueprint * @return Blueprint
*/ */
public function expire($columns, $seconds) public function expire($columns, $seconds)
...@@ -221,7 +223,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -221,7 +223,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify a sparse and unique index for the collection. * Specify a sparse and unique index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @param array $options * @param array $options
* @return Blueprint * @return Blueprint
*/ */
public function sparse_and_unique($columns = null, $options = []) public function sparse_and_unique($columns = null, $options = [])
......
<?php namespace Jenssegers\Mongodb\Schema; <?php
namespace Jenssegers\Mongodb\Schema;
use Closure; use Closure;
use Jenssegers\Mongodb\Connection; use Jenssegers\Mongodb\Connection;
...@@ -59,7 +61,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -59,7 +61,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
/** /**
* Modify a collection on the schema. * Modify a collection on the schema.
* *
* @param string $collection * @param string $collection
* @param Closure $callback * @param Closure $callback
* @return bool * @return bool
*/ */
......
<?php namespace Jenssegers\Mongodb\Schema; <?php
namespace Jenssegers\Mongodb\Schema;
use Illuminate\Database\Schema\Grammars\Grammar as BaseGrammar; use Illuminate\Database\Schema\Grammars\Grammar as BaseGrammar;
......
<?php namespace Jenssegers\Mongodb\Validation; <?php
namespace Jenssegers\Mongodb\Validation;
class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVerifier class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVerifier
{ {
/** /**
* Count the number of objects in a collection having the given value. * Count the number of objects in a collection having the given value.
* *
* @param string $collection * @param string $collection
* @param string $column * @param string $column
* @param string $value * @param string $value
* @param int $excludeId * @param int $excludeId
* @param string $idColumn * @param string $idColumn
* @param array $extra * @param array $extra
* @return int * @return int
*/ */
public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = []) public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = [])
{ {
$query = $this->table($collection)->where($column, 'regex', "/$value/i"); $query = $this->table($collection)->where($column, 'regex', "/$value/i");
if (! is_null($excludeId) && $excludeId != 'NULL') { if (!is_null($excludeId) && $excludeId != 'NULL') {
$query->where($idColumn ?: 'id', '<>', $excludeId); $query->where($idColumn ?: 'id', '<>', $excludeId);
} }
...@@ -31,17 +33,17 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe ...@@ -31,17 +33,17 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
/** /**
* Count the number of objects in a collection with the given values. * Count the number of objects in a collection with the given values.
* *
* @param string $collection * @param string $collection
* @param string $column * @param string $column
* @param array $values * @param array $values
* @param array $extra * @param array $extra
* @return int * @return int
*/ */
public function getMultiCount($collection, $column, array $values, array $extra = []) public function getMultiCount($collection, $column, array $values, array $extra = [])
{ {
// Generates a regex like '/(a|b|c)/i' which can query multiple values // Generates a regex like '/(a|b|c)/i' which can query multiple values
$regex = '/('.implode('|', $values).')/i'; $regex = '/(' . implode('|', $values) . ')/i';
$query = $this->table($collection)->where($column, 'regex', $regex); $query = $this->table($collection)->where($column, 'regex', $regex);
foreach ($extra as $key => $extraValue) { foreach ($extra as $key => $extraValue) {
......
<?php namespace Jenssegers\Mongodb\Validation; <?php
namespace Jenssegers\Mongodb\Validation;
use Illuminate\Validation\ValidationServiceProvider as BaseProvider; use Illuminate\Validation\ValidationServiceProvider as BaseProvider;
......
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