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 DateTimeZone;
......
<?php namespace Jenssegers\Mongodb\Auth;
<?php
namespace Jenssegers\Mongodb\Auth;
use Illuminate\Auth\Passwords\PasswordResetServiceProvider as BasePasswordResetServiceProvider;
......
<?php namespace Jenssegers\Mongodb\Auth;
<?php
namespace Jenssegers\Mongodb\Auth;
use Illuminate\Auth\Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Model;
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\Authenticatable as AuthenticatableContract;
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
AuthenticatableContract,
......
<?php namespace Jenssegers\Mongodb;
<?php
namespace Jenssegers\Mongodb;
use Exception;
use MongoDB\BSON\ObjectID;
......@@ -21,7 +23,7 @@ class Collection
protected $collection;
/**
* @param Connection $connection
* @param Connection $connection
* @param MongoCollection $collection
*/
public function __construct(Connection $connection, MongoCollection $collection)
......@@ -34,7 +36,7 @@ class Collection
* Handle dynamic method calls.
*
* @param string $method
* @param array $parameters
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
......@@ -53,7 +55,7 @@ class Collection
// Convert the query parameters to a json string.
array_walk_recursive($parameters, function (&$item, $key) {
if ($item instanceof ObjectID) {
$item = (string) $item;
$item = (string)$item;
}
});
......@@ -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);
}
......
<?php namespace Jenssegers\Mongodb;
<?php
namespace Jenssegers\Mongodb;
use Illuminate\Database\Connection as BaseConnection;
use MongoDB\Client;
......@@ -114,8 +116,8 @@ class Connection extends BaseConnection
* Create a new MongoDB connection.
*
* @param string $dsn
* @param array $config
* @param array $options
* @param array $config
* @param array $options
* @return \MongoDB\Client
*/
protected function createConnection($dsn, array $config, array $options)
......@@ -128,10 +130,10 @@ class Connection extends BaseConnection
}
// 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'];
}
if (! isset($options['password']) && ! empty($config['password'])) {
if (!isset($options['password']) && !empty($config['password'])) {
$options['password'] = $config['password'];
}
......@@ -155,7 +157,7 @@ class Connection extends BaseConnection
protected function getDsn(array $config)
{
// Check if the user passed a complete dsn to the configuration.
if (! empty($config['dsn'])) {
if (!empty($config['dsn'])) {
return $config['dsn'];
}
......@@ -164,15 +166,15 @@ class Connection extends BaseConnection
foreach ($hosts as &$host) {
// Check if we need to add a port to the host
if (strpos($host, ':') === false && ! empty($config['port'])) {
$host = $host.':'.$config['port'];
if (strpos($host, ':') === false && !empty($config['port'])) {
$host = $host . ':' . $config['port'];
}
}
// 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
* Dynamically pass methods to the connection.
*
* @param string $method
* @param array $parameters
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
......
<?php namespace Jenssegers\Mongodb\Eloquent;
<?php
namespace Jenssegers\Mongodb\Eloquent;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Jenssegers\Mongodb\Helpers\QueriesRelationships;
......@@ -8,6 +10,7 @@ use MongoDB\Model\BSONDocument;
class Builder extends EloquentBuilder
{
use QueriesRelationships;
/**
* The methods that should be returned from query builder.
*
......@@ -157,10 +160,10 @@ class Builder extends EloquentBuilder
elseif ($results instanceof BSONDocument) {
$results = $results->getArrayCopy();
return $this->model->newFromBuilder((array) $results);
return $this->model->newFromBuilder((array)$results);
} // The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results)) {
return $this->model->newFromBuilder((array) $results);
return $this->model->newFromBuilder((array)$results);
}
return $results;
......
<?php namespace Jenssegers\Mongodb\Eloquent;
<?php
namespace Jenssegers\Mongodb\Eloquent;
use Jenssegers\Mongodb\Relations\EmbedsMany;
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\MorphOne;
......@@ -23,7 +25,7 @@ trait HybridRelations
public function hasOne($related, $foreignKey = null, $localKey = null)
{
// 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);
}
......@@ -49,7 +51,7 @@ trait HybridRelations
public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
{
// 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);
}
......@@ -73,7 +75,7 @@ trait HybridRelations
public function hasMany($related, $foreignKey = null, $localKey = null)
{
// 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);
}
......@@ -99,7 +101,7 @@ trait HybridRelations
public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
{
// 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);
}
......@@ -138,7 +140,7 @@ trait HybridRelations
}
// 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);
}
......@@ -146,7 +148,7 @@ trait HybridRelations
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey)) {
$foreignKey = Str::snake($relation).'_id';
$foreignKey = Str::snake($relation) . '_id';
}
$instance = new $related;
......@@ -225,18 +227,18 @@ trait HybridRelations
}
// 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);
}
// 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
// instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey().'s';
$foreignKey = $foreignKey ?: $this->getForeignKey() . 's';
$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
// models using underscores in alphabetical order. The two model names
......
<?php namespace Jenssegers\Mongodb\Eloquent;
<?php
namespace Jenssegers\Mongodb\Eloquent;
use Carbon\Carbon;
use DateTime;
......@@ -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.
// 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'];
}
// Convert ObjectID to string.
if ($value instanceof ObjectID) {
return (string) $value;
return (string)$value;
}
return $value;
......@@ -75,7 +77,7 @@ abstract class Model extends BaseModel
}
// Let Eloquent convert the value to a DateTime instance.
if (! $value instanceof DateTime) {
if (!$value instanceof DateTime) {
$value = parent::asDateTime($value);
}
......@@ -124,7 +126,7 @@ abstract class Model extends BaseModel
*/
public function getAttribute($key)
{
if (! $key) {
if (!$key) {
return;
}
......@@ -134,7 +136,7 @@ abstract class Model extends BaseModel
}
// 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);
}
......@@ -191,14 +193,14 @@ abstract class Model extends BaseModel
// nicely when your models are converted to JSON.
foreach ($attributes as $key => &$value) {
if ($value instanceof ObjectID) {
$value = (string) $value;
$value = (string)$value;
}
}
// Convert dot-notation dates.
foreach ($this->getDates() as $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
*/
public function drop($columns)
{
if (! is_array($columns)) {
if (!is_array($columns)) {
$columns = [$columns];
}
......@@ -268,7 +270,7 @@ abstract class Model extends BaseModel
}
// Do batch push by default.
if (! is_array($values)) {
if (!is_array($values)) {
$values = [$values];
}
......@@ -286,13 +288,13 @@ abstract class Model extends BaseModel
* Remove one or more values from an array.
*
* @param string $column
* @param mixed $values
* @param mixed $values
* @return mixed
*/
public function pull($column, $values)
{
// Do batch pull by default.
if (! is_array($values)) {
if (!is_array($values)) {
$values = [$values];
}
......@@ -307,8 +309,8 @@ abstract class Model extends BaseModel
* Append one or more values to the underlying attribute value and sync with original.
*
* @param string $column
* @param array $values
* @param bool $unique
* @param array $values
* @param bool $unique
*/
protected function pushAttributeValues($column, array $values, $unique = false)
{
......@@ -332,7 +334,7 @@ abstract class Model extends BaseModel
* Remove one or more values to the underlying attribute value and sync with original.
*
* @param string $column
* @param array $values
* @param array $values
*/
protected function pullAttributeValues($column, array $values)
{
......@@ -356,7 +358,7 @@ abstract class Model extends BaseModel
*/
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
{
......
......@@ -86,7 +86,7 @@ trait QueriesRelationships
$not = in_array($operator, ['<', '<=', '!=']);
// If we are comparing to 0, we need an additional $not flip.
if ($count == 0) {
$not = ! $not;
$not = !$not;
}
$relations = $hasQuery->pluck($this->getHasCompareKey($relation));
......@@ -112,7 +112,7 @@ trait QueriesRelationships
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
protected function getConstrainedRelatedIds($relations, $operator, $count)
{
$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()));
// Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use ($count, $operator) {
......
<?php namespace Jenssegers\Mongodb;
<?php
namespace Jenssegers\Mongodb;
use Illuminate\Queue\QueueServiceProvider;
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
......
<?php namespace Jenssegers\Mongodb;
<?php
namespace Jenssegers\Mongodb;
use Illuminate\Support\ServiceProvider;
use Jenssegers\Mongodb\Eloquent\Model;
......
<?php namespace Jenssegers\Mongodb\Query;
<?php
namespace Jenssegers\Mongodb\Query;
use Closure;
use DateTime;
......@@ -237,18 +239,18 @@ class Builder extends BaseBuilder
// Add grouping columns to the $group part of the aggregation pipeline.
if ($this->groups) {
foreach ($this->groups as $column) {
$group['_id'][$column] = '$'.$column;
$group['_id'][$column] = '$' . $column;
// When grouping, also add the $last operator to each grouped field,
// this mimics MySQL's behaviour a bit.
$group[$column] = ['$last' => '$'.$column];
$group[$column] = ['$last' => '$' . $column];
}
// Do the same for other columns that are selected.
foreach ($this->columns as $column) {
$key = str_replace('.', '_', $column);
$group[$key] = ['$last' => '$'.$column];
$group[$key] = ['$last' => '$' . $column];
}
}
......@@ -270,7 +272,7 @@ class Builder extends BaseBuilder
$group['aggregate'] = ['$sum' => 1];
} // Pass other functions directly.
else {
$group['aggregate'] = ['$'.$function => '$'.$column];
$group['aggregate'] = ['$' . $function => '$' . $column];
}
}
}
......@@ -296,7 +298,7 @@ class Builder extends BaseBuilder
// apply unwinds for subdocument array aggregation
foreach ($unwinds as $unwind) {
$pipeline[] = ['$unwind' => '$'.$unwind];
$pipeline[] = ['$unwind' => '$' . $unwind];
}
if ($group) {
......@@ -422,28 +424,28 @@ class Builder extends BaseBuilder
public function aggregate($function, $columns = [])
{
$this->aggregate = compact('function', 'columns');
$previousColumns = $this->columns;
// 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
// we will add the bindings back onto this query so they can get used.
$previousSelectBindings = $this->bindings['select'];
$this->bindings['select'] = [];
$results = $this->get($columns);
// Once we have executed the query, we will reset the aggregate property so
// that more select queries can be executed against the database without
// the aggregate value getting in the way when the grammar builds it.
$this->aggregate = null;
$this->columns = $previousColumns;
$this->bindings['select'] = $previousSelectBindings;
if (isset($results[0])) {
$result = (array) $results[0];
$result = (array)$results[0];
return $result['aggregate'];
}
}
......@@ -453,7 +455,7 @@ class Builder extends BaseBuilder
*/
public function exists()
{
return ! is_null($this->first());
return !is_null($this->first());
}
/**
......@@ -522,20 +524,20 @@ class Builder extends BaseBuilder
foreach ($values as $value) {
// As soon as we find a value that is not an array we assume the user is
// inserting a single document.
if (! is_array($value)) {
if (!is_array($value)) {
$batch = false;
break;
}
}
if (! $batch) {
if (!$batch) {
$values = [$values];
}
// Batch insert
$result = $this->collection->insertMany($values);
return (1 == (int) $result->isAcknowledged());
return (1 == (int)$result->isAcknowledged());
}
/**
......@@ -545,7 +547,7 @@ class Builder extends BaseBuilder
{
$result = $this->collection->insertOne($values);
if (1 == (int) $result->isAcknowledged()) {
if (1 == (int)$result->isAcknowledged()) {
if (is_null($sequence)) {
$sequence = '_id';
}
......@@ -561,7 +563,7 @@ class Builder extends BaseBuilder
public function update(array $values, array $options = [])
{
// Use $set as default operator.
if (! starts_with(key($values), '$')) {
if (!starts_with(key($values), '$')) {
$values = ['$set' => $values];
}
......@@ -575,7 +577,7 @@ class Builder extends BaseBuilder
{
$query = ['$inc' => [$column => $amount]];
if (! empty($extra)) {
if (!empty($extra)) {
$query['$set'] = $extra;
}
......@@ -607,7 +609,7 @@ class Builder extends BaseBuilder
// Convert ObjectID's to strings
if ($key == '_id') {
$results = $results->map(function ($item) {
$item['_id'] = (string) $item['_id'];
$item['_id'] = (string)$item['_id'];
return $item;
});
}
......@@ -624,13 +626,13 @@ class Builder extends BaseBuilder
// 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
// from their database without manually specifying the where clauses.
if (! is_null($id)) {
if (!is_null($id)) {
$this->where('_id', '=', $id);
}
$wheres = $this->compileWheres();
$result = $this->collection->DeleteMany($wheres);
if (1 == (int) $result->isAcknowledged()) {
if (1 == (int)$result->isAcknowledged()) {
return $result->getDeletedCount();
}
......@@ -656,7 +658,7 @@ class Builder extends BaseBuilder
{
$result = $this->collection->drop();
return (1 == (int) $result->ok);
return (1 == (int)$result->ok);
}
/**
......@@ -681,7 +683,7 @@ class Builder extends BaseBuilder
if ($expression instanceof Closure) {
return call_user_func($expression, $this->collection);
} // Create an expression for the given value
elseif (! is_null($expression)) {
elseif (!is_null($expression)) {
return new Expression($expression);
}
......@@ -694,7 +696,7 @@ class Builder extends BaseBuilder
*
* @param mixed $column
* @param mixed $value
* @param bool $unique
* @param bool $unique
* @return int
*/
public function push($column, $value = null, $unique = false)
......@@ -748,7 +750,7 @@ class Builder extends BaseBuilder
*/
public function drop($columns)
{
if (! is_array($columns)) {
if (!is_array($columns)) {
$columns = [$columns];
}
......@@ -781,13 +783,13 @@ class Builder extends BaseBuilder
protected function performUpdate($query, array $options = [])
{
// Update multiple items by default.
if (! array_key_exists('multiple', $options)) {
if (!array_key_exists('multiple', $options)) {
$options['multiple'] = true;
}
$wheres = $this->compileWheres();
$result = $this->collection->UpdateMany($wheres, $query, $options);
if (1 == (int) $result->isAcknowledged()) {
if (1 == (int)$result->isAcknowledged()) {
return $result->getModifiedCount() ? $result->getModifiedCount() : $result->getUpsertedCount();
}
......@@ -936,18 +938,18 @@ class Builder extends BaseBuilder
$regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value));
// Convert like to regular expression.
if (! starts_with($value, '%')) {
$regex = '^'.$regex;
if (!starts_with($value, '%')) {
$regex = '^' . $regex;
}
if (! ends_with($value, '%')) {
$regex = $regex.'$';
if (!ends_with($value, '%')) {
$regex = $regex . '$';
}
$value = new Regex($regex, 'i');
} // Manipulate regexp operations.
elseif (in_array($operator, ['regexp', 'not regexp', 'regex', 'not regex'])) {
// Automatically convert regular expression strings to Regex objects.
if (! $value instanceof Regex) {
if (!$value instanceof Regex) {
$e = explode('/', $value);
$flag = end($e);
$regstr = substr($value, 1, -(strlen($flag) + 1));
......@@ -961,12 +963,12 @@ class Builder extends BaseBuilder
}
}
if (! isset($operator) or $operator == '=') {
if (!isset($operator) or $operator == '=') {
$query = [$column => $value];
} elseif (array_key_exists($operator, $this->conversion)) {
$query = [$column => [$this->conversion[$operator] => $value]];
} else {
$query = [$column => ['$'.$operator => $value]];
$query = [$column => ['$' . $operator => $value]];
}
return $query;
......
<?php namespace Jenssegers\Mongodb\Query;
<?php
namespace Jenssegers\Mongodb\Query;
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;
......
<?php namespace Jenssegers\Mongodb\Queue\Failed;
<?php
namespace Jenssegers\Mongodb\Queue\Failed;
use Carbon\Carbon;
use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
......@@ -31,7 +33,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
$all = $this->getTable()->orderBy('_id', 'desc')->get()->all();
$all = array_map(function ($job) {
$job['id'] = (string) $job['_id'];
$job['id'] = (string)$job['_id'];
return $job;
}, $all);
......@@ -41,14 +43,14 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
/**
* Get a single failed job.
*
* @param mixed $id
* @param mixed $id
* @return array
*/
public function find($id)
{
$job = $this->getTable()->find($id);
$job['id'] = (string) $job['_id'];
$job['id'] = (string)$job['_id'];
return $job;
}
......@@ -56,7 +58,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
/**
* Delete a single failed job from storage.
*
* @param mixed $id
* @param mixed $id
* @return bool
*/
public function forget($id)
......
<?php namespace Jenssegers\Mongodb\Queue;
<?php
namespace Jenssegers\Mongodb\Queue;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Queue\Connectors\ConnectorInterface;
......@@ -16,8 +18,7 @@ class MongoConnector implements ConnectorInterface
/**
* Create a new connector instance.
*
* @param \Illuminate\Database\ConnectionResolverInterface $connections
* @return void
* @param \Illuminate\Database\ConnectionResolverInterface $connections
*/
public function __construct(ConnectionResolverInterface $connections)
{
......@@ -27,7 +28,7 @@ class MongoConnector implements ConnectorInterface
/**
* Establish a queue connection.
*
* @param array $config
* @param array $config
* @return \Illuminate\Contracts\Queue\Queue
*/
public function connect(array $config)
......
<?php namespace Jenssegers\Mongodb\Queue;
<?php
namespace Jenssegers\Mongodb\Queue;
use Illuminate\Queue\Jobs\DatabaseJob;
......
<?php namespace Jenssegers\Mongodb\Queue;
<?php
namespace Jenssegers\Mongodb\Queue;
use Carbon\Carbon;
use Illuminate\Queue\DatabaseQueue;
......@@ -37,7 +39,7 @@ class MongoQueue extends DatabaseQueue
{
$queue = $this->getQueue($queue);
if (! is_null($this->retryAfter)) {
if (!is_null($this->retryAfter)) {
$this->releaseJobsThatHaveBeenReservedTooLong($queue);
}
......@@ -124,7 +126,7 @@ class MongoQueue extends DatabaseQueue
* Release the given job ID from reservation.
*
* @param string $id
* @param int $attempts
* @param int $attempts
* @return void
*/
protected function releaseJob($id, $attempts)
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder;
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
......@@ -144,8 +146,8 @@ class BelongsToMany extends EloquentBelongsToMany
if ($detaching and count($detach) > 0) {
$this->detach($detach);
$changes['detached'] = (array) array_map(function ($v) {
return is_numeric($v) ? (int) $v : (string) $v;
$changes['detached'] = (array)array_map(function ($v) {
return is_numeric($v) ? (int)$v : (string)$v;
}, $detach);
}
......@@ -190,14 +192,14 @@ class BelongsToMany extends EloquentBelongsToMany
$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.
$query->push($this->foreignKey, $this->parent->getKey(), true);
}
// 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) {
$this->touchIfTouching();
......@@ -210,7 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany
public function detach($ids = [], $touch = true)
{
if ($ids instanceof Model) {
$ids = (array) $ids->getKey();
$ids = (array)$ids->getKey();
}
$query = $this->newRelatedQuery();
......@@ -218,7 +220,7 @@ class BelongsToMany extends EloquentBelongsToMany
// If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken.
// 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.
$this->parent->pull($this->getRelatedKey(), $ids);
......@@ -307,7 +309,7 @@ class BelongsToMany extends EloquentBelongsToMany
{
$results = [];
foreach ($records as $id => $attributes) {
if (! is_array($attributes)) {
if (!is_array($attributes)) {
list($id, $attributes) = [$attributes, []];
}
$results[$id] = $attributes;
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
......@@ -37,7 +39,7 @@ class EmbedsMany extends EmbedsOneOrMany
public function performInsert(Model $model)
{
// 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);
}
......@@ -77,10 +79,10 @@ class EmbedsMany extends EmbedsOneOrMany
$foreignKey = $this->getForeignKeyValue($model);
// 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.
$result = $this->getBaseQuery()->where($this->localKey.'.'.$model->getKeyName(), $foreignKey)
$result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey)
->update($values);
// Attach the model to its parent.
......@@ -126,7 +128,7 @@ class EmbedsMany extends EmbedsOneOrMany
*/
public function associate(Model $model)
{
if (! $this->contains($model)) {
if (!$this->contains($model)) {
return $this->associateNew($model);
} else {
return $this->associateExisting($model);
......@@ -235,7 +237,7 @@ class EmbedsMany extends EmbedsOneOrMany
protected function associateNew($model)
{
// Create a new key if needed.
if (! $model->getAttribute('_id')) {
if (!$model->getAttribute('_id')) {
$model->setAttribute('_id', new ObjectID);
}
......@@ -309,7 +311,7 @@ class EmbedsMany extends EmbedsOneOrMany
*/
protected function setEmbedded($models)
{
if (! is_array($models)) {
if (!is_array($models)) {
$models = [$models];
}
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Model;
use MongoDB\BSON\ObjectID;
......@@ -34,7 +36,7 @@ class EmbedsOne extends EmbedsOneOrMany
public function performInsert(Model $model)
{
// 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);
}
......@@ -69,7 +71,7 @@ class EmbedsOne extends EmbedsOneOrMany
}
// 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);
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
......@@ -32,11 +34,11 @@ abstract class EmbedsOneOrMany extends Relation
* Create a new embeds many relationship instance.
*
* @param Builder $query
* @param Model $parent
* @param Model $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @param Model $parent
* @param Model $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
*/
public function __construct(Builder $query, Model $parent, Model $related, $localKey, $foreignKey, $relation)
{
......@@ -186,7 +188,7 @@ abstract class EmbedsOneOrMany extends Relation
$ids = $ids->all();
}
if (! is_array($ids)) {
if (!is_array($ids)) {
$ids = [$ids];
}
......@@ -208,7 +210,7 @@ abstract class EmbedsOneOrMany extends Relation
$attributes = $this->parent->getAttributes();
// 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;
}
......@@ -278,7 +280,7 @@ abstract class EmbedsOneOrMany extends Relation
return;
}
$model = $this->related->newFromBuilder((array) $attributes);
$model = $this->related->newFromBuilder((array)$attributes);
$model->setParentRelation($this);
......@@ -339,7 +341,7 @@ abstract class EmbedsOneOrMany extends Relation
protected function getPathHierarchy($glue = '.')
{
if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy($glue).$glue.$this->localKey;
return $parentRelation->getPathHierarchy($glue) . $glue . $this->localKey;
}
return $this->localKey;
......@@ -351,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation
public function getQualifiedParentKeyName()
{
if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy().'.'.$this->parent->getKeyName();
return $parentRelation->getPathHierarchy() . '.' . $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\Relations\HasMany as EloquentHasMany;
......@@ -62,8 +64,8 @@ class HasMany extends EloquentHasMany
/**
* Add the constraints for a relationship query.
*
* @param Builder $query
* @param Builder $parent
* @param Builder $query
* @param Builder $parent
* @param array|mixed $columns
* @return Builder
*/
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
......@@ -62,8 +64,8 @@ class HasOne extends EloquentHasOne
/**
* Add the constraints for a relationship query.
*
* @param Builder $query
* @param Builder $parent
* @param Builder $query
* @param Builder $parent
* @param array|mixed $columns
* @return Builder
*/
......
<?php namespace Jenssegers\Mongodb\Relations;
<?php
namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
......
<?php namespace Jenssegers\Mongodb\Schema;
<?php
namespace Jenssegers\Mongodb\Schema;
use Illuminate\Database\Connection;
......@@ -84,7 +86,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
$transform = [];
foreach ($columns as $column) {
$transform[$column] = $column.'_1';
$transform[$column] = $column . '_1';
}
$columns = $transform;
......@@ -130,7 +132,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify a sparse index for the collection.
*
* @param string|array $columns
* @param array $options
* @param array $options
* @return Blueprint
*/
public function sparse($columns = null, $options = [])
......@@ -148,8 +150,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify a geospatial index for the collection.
*
* @param string|array $columns
* @param string $index
* @param array $options
* @param string $index
* @param array $options
* @return Blueprint
*/
public function geospatial($columns = null, $index = '2d', $options = [])
......@@ -174,7 +176,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* on the given single-field index containing a date.
*
* @param string|array $columns
* @param int $seconds
* @param int $seconds
* @return Blueprint
*/
public function expire($columns, $seconds)
......@@ -221,7 +223,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify a sparse and unique index for the collection.
*
* @param string|array $columns
* @param array $options
* @param array $options
* @return Blueprint
*/
public function sparse_and_unique($columns = null, $options = [])
......
<?php namespace Jenssegers\Mongodb\Schema;
<?php
namespace Jenssegers\Mongodb\Schema;
use Closure;
use Jenssegers\Mongodb\Connection;
......@@ -59,7 +61,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
/**
* Modify a collection on the schema.
*
* @param string $collection
* @param string $collection
* @param Closure $callback
* @return bool
*/
......
<?php namespace Jenssegers\Mongodb\Schema;
<?php
namespace Jenssegers\Mongodb\Schema;
use Illuminate\Database\Schema\Grammars\Grammar as BaseGrammar;
......
<?php namespace Jenssegers\Mongodb\Validation;
<?php
namespace Jenssegers\Mongodb\Validation;
class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVerifier
{
/**
* Count the number of objects in a collection having the given value.
*
* @param string $collection
* @param string $column
* @param string $value
* @param int $excludeId
* @param string $idColumn
* @param array $extra
* @param string $collection
* @param string $column
* @param string $value
* @param int $excludeId
* @param string $idColumn
* @param array $extra
* @return int
*/
public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = [])
{
$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);
}
......@@ -31,17 +33,17 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
/**
* Count the number of objects in a collection with the given values.
*
* @param string $collection
* @param string $column
* @param array $values
* @param array $extra
* @param string $collection
* @param string $column
* @param array $values
* @param array $extra
* @return int
*/
public function getMultiCount($collection, $column, array $values, array $extra = [])
{
// 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);
foreach ($extra as $key => $extraValue) {
......
<?php namespace Jenssegers\Mongodb\Validation;
<?php
namespace Jenssegers\Mongodb\Validation;
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